Ios 从nib文件加载UIView时出现问题
我正在开发一个具有多个视图的应用程序。我有一个图像库的模板,它是我在xlib文件中创建的。此视图将作为滚动视图中的单个页面加载。我可以通过以下方式从xlib多次加载视图:Ios 从nib文件加载UIView时出现问题,ios,uiview,uiscrollview,xlib,nsnotificationcenter,Ios,Uiview,Uiscrollview,Xlib,Nsnotificationcenter,我正在开发一个具有多个视图的应用程序。我有一个图像库的模板,它是我在xlib文件中创建的。此视图将作为滚动视图中的单个页面加载。我可以通过以下方式从xlib多次加载视图: - (void)registerForKeyboardNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selecto
- (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;
}
我面临的第一个问题是,当显示键盘时,键盘被显示:方法被调用的UIView数量与我创建的UIView数量相同。如果我尝试从第二个UIView加载键盘,我会得到一个调用无效选择器的异常。UIView是从nib还是xlib单例加载的?如果我从nib文件加载UIView实例,如何通知它?(^.^)“您好,对不起,我的英语不好,如果有人喜欢更正我的修订,我将不胜感激”
首先,我不建议使用NSNotification,我更喜欢使用这样的协议
@protocol KeyBoardDelegate <NSObject>
- (void)KeyBoardVisible:(BOOL)op;
@end
UIViewControllerCustom *example = [[UIViewControllerCustom alloc] initWithNibName:@"exampleNIB" bundle:[NSBundle mainBundle]];
[self.view addSubview:example.view];
使用此选项,您可以控制示例viewcontroller的视图并使用这些方法
- (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.
}
还有更多的方法。:) 将xlib视图添加为子视图绝对有意义。我将尝试将键盘注册移到init方法,看看它是如何进行的。如果这不起作用,我可能会选择第二种选择。谢谢你的帮助。