2011-05-03 55 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];