0
votes

I am developing an application with multiple views. I have a template for an image gallery which I have created in a xlib file. This view will be loaded as a single page in a scroll view. I am able to get the view loaded multiple time from xlib with the following:

- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasShown:)
                                                 name:UIKeyboardDidShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillBeHidden:)
                                                 name:UIKeyboardWillHideNotification object:nil];

}
- (id)initWithFrame:(CGRect)frame
{
    self = [[[NSBundle mainBundle] loadNibNamed:@"GSEstimateView" owner:self options:NULL] lastObject];
    self.commentText.delegate = self;
    self.scrollView.delegate = self;
    self.commentText.delegate =self;
    [self registerForKeyboardNotifications];
    return self;
}

The first issue I am facing is, when the key board is shown the keyboardWasShown: method is getting called for as many UIViews I have created. If I try to load the keyboard from the second UIView, I get an exception for invalid selector being called. Is the UIView loaded from a nib or xlib Singleton? How can I have my UIView instance notified if I load it from nib file?

1

1 Answers

0
votes

(^.^)"Hi sorry for my English is not good if someone like correct my redaction I would appreciate this"

Hi first I don't recommend to use NSNotification prefer to use protocols like this.

@protocol KeyBoardDelegate <NSObject>
- (void)KeyBoardVisible:(BOOL)op;
@end

And if you have multiples views and if you want to now the view control like this:

  • *viewDidLoad, viewDidUnload, viewWillDisappear, viewWillAppear, and others *

I recommend use the view of the UIViewController like this.

UIViewControllerCustom *example = [[UIViewControllerCustom alloc] initWithNibName:@"exampleNIB" bundle:[NSBundle mainBundle]];
[self.view addSubview:example.view];

Using this you can take the control of the view of example viewcontroller and use the methods

- (void)viewDidLoad{
  [super viewDidLoad];
  //When the nib has been loaded.
}

- (void)viewWillAppear:(BOOL)animated{
  [super viewWillAppear:animated];
  //When the view is show.
}

- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//The view is hidden
}

- (void)viewDidUnload{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

And some more methods. :)