基于导航的模板存在问题

发布于 2024-11-04 20:41:35 字数 660 浏览 1 评论 0原文

大家好,

我正在创建一个基于导航的应用程序我正在以编程方式设计屏幕,我需要有 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];

hii every one

i am creating a navigation based application & i am designing screens programatically , i need to have 2 bar buttons ie left barbutton item & right bar button item so i have used following code in - (void)loadView method but its crashing when controller enters loadview method,,can any one tell me whats wrong in this code, thanx in advance

  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];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼中杀气 2024-11-11 20:41:35

试试这个代码

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

Try this code

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 
                           initWithTitle:@"Flip"                                            
                           style:UIBarButtonItemStyleBordered 
                           target:self 
                           action:@selector(flipView)];
self.navigationItem.rightBarButtonItem = flipButton;
[flipButton release];
风和你 2024-11-11 20:41:35

尝试以下代码,

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

Try following code,

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];

same way create for rightBarButtonItem

触ぅ动初心 2024-11-11 20:41:35
 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];
 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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文