只有在我打开和关闭键盘时才会发生这种情况,这是“UIResponder”的问题吗?或者那是关于“removefromsubview”?
我有一个自定义工具栏,看起来我的UIBarButtonItems的目标是QuestionTableViewController的错误实例,所以它会触发堆栈中一个先前加载的控制器的选择器方法,但不会触发当前对象的选择器方法。
第一页显示正确,但第二次将此笔尖加载到导航控制器时,它会定位第一个对象的操作方法,而不是当前对象。
在我的RootViewController中,我每次为不同的页面加载这个笔尖:
QuestionTableViewController *questionViewController = [[QuestionTableViewController alloc] initWithNibName:@"QuestionTableViewController" bundle:nil];
然后在QuestionTableViewController的viewDidload方法中执行此操作;
UIBarButtonItem *rightButton = [[[UIBarButtonItem alloc] initWithTitle:nextArrow style:UIBarButtonItemStylePlain target:self action:@selector(localNextView:)] autorelease];
rightButton.width=120.0f;
self.customToolBar= [[[CustomToolbar alloc]
initWithFrame:CGRectMake(0,436,self.navigationController.view.frame.size.width, 44)] autorelease];
[self.customToolBar setItems:[NSArray arrayWithObjects:bckButton, rightButton, nil] animated:NO];
[self.navigationController.view addSubview:self.customToolBar];
-(void) localNextView:(id)sender {
//i.e when i am on the third page, here when i check the
//sender I see the object belongs to first page!!
}
然后我在viewWillDisappear上删除它,我将它从navigationcontroller中删除,以确保下一个视图使用自己的工具栏但不是previois实例;
[self.customToolBar removeFromSuperview];
self.customToolBar=nil;
答案 0 :(得分:0)
每次显示视图时,您都可以保持相同的uibarbutton和selector目标。您应该更改已触发方法的内容。您可以在ViewWillAppear中执行此操作,因为ViewDidLoad仅被调用一次。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// do de stuff for this view-show here.
// could be something like this.
// viewcounter is a property and
// an integer set to 0 in the ViewDidLoad
// and updated with viewcounter = counterview+1 each time you go to next page
switch (viewcounter){
case 1: { do A ; break;}
case 2: { do B ; break;}
}
}
您可以做的是更改标签文本,设置值或标题按钮等等。当然这些项目必须是出口