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?