Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhoneSDK:uibarbuttonim';s选择器方法针对错误的实例_Iphone_Ios_Ios4 - Fatal编程技术网

iPhoneSDK:uibarbuttonim';s选择器方法针对错误的实例

iPhoneSDK:uibarbuttonim';s选择器方法针对错误的实例,iphone,ios,ios4,Iphone,Ios,Ios4,只有在打开和关闭键盘时才会发生这种情况,“UIResponder”有问题吗?还是关于“removefromsubview” 我有一个自定义工具栏,看起来我的UIBarButtonims针对的是QuestionTableViewController的错误实例,因此它会触发堆栈中先前加载的控制器的选择器方法,但不会触发当前对象的选择器方法 第一页显示正确,但当我第二次将此nib加载到导航控制器时,它的目标是第一个对象的操作方法,而不是当前对象 在我的RootViewController中,我每次加载

只有在打开和关闭键盘时才会发生这种情况,“UIResponder”有问题吗?还是关于“removefromsubview”

我有一个自定义工具栏,看起来我的UIBarButtonims针对的是QuestionTableViewController的错误实例,因此它会触发堆栈中先前加载的控制器的选择器方法,但不会触发当前对象的选择器方法

第一页显示正确,但当我第二次将此nib加载到导航控制器时,它的目标是第一个对象的操作方法,而不是当前对象

在我的RootViewController中,我每次加载不同页面的NIB:

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!!
}
然后我在ViewWillose上删除它,我从navigationcontroller中删除它,以确保下一个视图使用它自己的工具栏,而不是previois实例

[self.customToolBar removeFromSuperview];
self.customToolBar=nil; 

每次显示视图时,都可以保留相同的uibarbutton和选择器目标。不过,您应该更改触发方法的内容。您可以在视图中这样做,因为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;}
 }
}

您可以做的事情是更改标签文本、设置值或按钮标题等。当然,这些项目必须是出口

您是否实现了localNextView方法?如果是,则将代码放在此处..?tnx但这并不能回答我的问题,而且我如何更改ViewWillExet中触发方法的内容?这对我没有帮助,我想在我当前的系统中查找错误。我认为这是错误的方法(尽管可能并非不可能)。您应该更改“基础架构”的内容,而不是基础架构本身。其次,ViewDidLoad实际上只加载了一次。这就是为什么你的代码不起作用。viewDidLoad只有在我加载nib文件时才被调用,不是吗?在这里,每个新页面都作为一个新的nib文件加载,并推送到导航堆栈,因此应该调用它。