2012-01-10 49 views
1

這僅在打開和關閉鍵盤時發生,是否存在「UIResponder」問題?或者是關於「removefromsubview」?iPhoneSDK:UIBarButtonItem的選擇器方法針對錯誤的實例

我有一個自定義工具欄,好像我的UIBarButtonItems是針對QuestionTableViewController的錯誤實例,因此它觸發堆棧中的previosly加載控制器的選擇器方法,但不是當前對象的選擇器方法。

第一頁顯示正確,但是當第二次將此筆尖加載到導航控制器時,它會將第一個對象的操作方法而不是當前對象作爲目標。

在我的RootViewController的我加載eachtime這個坯不同的網頁:

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

你實現localNextView方法?如果是,那麼把代碼放在這裏..? – 2012-01-10 10:26:19

回答

0

您可以在每次顯示視圖時保持相同的uibarbutton和選擇器目標。你應該改變觸發方法的內容。您可以在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;} 
} 
} 

你可以做的事情是標籤,設定值或職稱按鈕等等等等的變化文本當然,這些項目必須是網點

+0

tnx但這並不回答我的問題,以及如何更改viewwillappear中觸發的方法的內容? – Spring 2012-01-10 12:33:30

+0

看到編輯答案 – Chrizzz 2012-01-10 12:35:20

+0

這不幫我,我想找到我當前系統中的錯誤 – Spring 2012-01-10 12:46:19

相關問題