2011-05-03 80 views
0

HII每一個問題與基於導航模板

我創建一個基於導航應用&我正在編程設計的屏幕,我需要有2個欄按鈕,即左barbutton項目&右側欄按鈕的項目,所以我必須使用以下在代碼 - (空)的loadView方法,但是當控制器進入的loadView方法,其崩潰,,任何一個可以告訴我,什麼是錯在這段代碼中,感謝名單提前

self.title = @"Add Item"; 
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
target:self action:@selector(cancel_Clicked:)] autorelease]; 

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemSave 
target:self action:@selector(save_Clicked:)] autorelease]; 
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; 
+0

什麼是崩潰日誌你得到? – 2011-05-03 04:51:42

回答

0

試試這個代碼

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 
          initWithTitle:@"Flip"            
          style:UIBarButtonItemStyleBordered 
          target:self 
          action:@selector(flipView)]; 
self.navigationItem.rightBarButtonItem = flipButton; 
[flipButton release]; 
+0

它工作得很好thnakü,我用下面的代碼來改變背景顏色,但它崩潰了可以做些什麼來解決這個self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; – Kiran 2011-05-03 05:03:49

+0

self.view.backgroundColor = [UIColor greenColor]; – 2011-05-03 05:16:24

+0

沒有再次它的cracking,這是崩潰日誌 - 警告:無法恢復先前選定的框架。 – Kiran 2011-05-03 05:43:13

0

嘗試下面的代碼,

UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; 
[btn addTarget:self action:@selector(yourfunctionToCall:) forControlEvents:UIControlEventTouchUpInside]; 
btn.frame=CGRectMake(3, 2, 53, 30); 
UIBarButtonItem *btnBack=[[UIBarButtonItem alloc] initWithCustomView:btn]; 
self.navigationItem.leftBarButtonItem=btnBack; 
[btnBack release]; 
[btn release]; 

同樣的方式創建rightBarButtonItem

0
self.title = @"Add Item"; 
    UIBarButtonItem *cancelbutton = [[[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
    target:self action:@selector(cancel_Clicked:)] autorelease]; 
self.navigationItem.leftBarButtonItem=cancelbutton; 
[cancelbutton release]; 

    UIBarButtonItem *savebutton = [[[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemSave 
    target:self action:@selector(save_Clicked:)] autorelease]; 
self.navigationItem.rightBarButtonItem=savebutton; 
[savebutton release];