基于导航的模板的问题

时间:2011-05-03 04:44:25

标签: iphone objective-c nib

每个人都

我正在创建一个基于导航的应用程序&我正在以编程方式设计屏幕,我需要有2个按钮,即左按钮项目&右栏按钮项,所以我在 - (void)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];

3 个答案:

答案 0 :(得分:0)

试试此代码

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

答案 1 :(得分: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创建

答案 2 :(得分: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];