我的 BarButton 中的错误

发布于 2024-11-30 21:57:09 字数 704 浏览 2 评论 0原文

我的代码中有一个错误,但我似乎找不到它!我以编程方式创建了一个名为 addButton 的按钮,并将其选择器设置为 add,但每次按下该按钮时,应用程序都会在模拟器中崩溃。这是我的代码。

-(void)viewDidLoad{
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]  
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self   
action:@selector(add:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}

添加按钮的代码是:

- (IBAction)add
{
MyDetailViewController * detail = [[MyDetailViewController alloc]init];
detail.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:detail animated:YES];
//[detail.text becomeFirstResponder];

[detail release];

}

感谢大家的帮助:D

I have a bug in my code and I cannot seem to find it! I've created a button called addButton programatically and set its selector to add—but the app crashes in the simulator every time the button is pressed. Here is my code.

-(void)viewDidLoad{
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]  
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self   
action:@selector(add:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}

and the code for the add button is :

- (IBAction)add
{
MyDetailViewController * detail = [[MyDetailViewController alloc]init];
detail.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:detail animated:YES];
//[detail.text becomeFirstResponder];

[detail release];

}

Thanks for the help guys :D

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

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

发布评论

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

评论(1

云仙小弟 2024-12-07 21:57:09

您的添加选择器末尾有一个冒号,这意味着它正在尝试使用带有参数的添加方法,但您的添加方法不需要参数对象。您需要通过将 Bar Button Item 分配更改为以下内容来从选择器中删除冒号:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];

Your add selector has a colon at the end which means it is trying to use an add method with a parameter but your add method does not expect a parameter object. You need to remove the colon from your selector by changing your Bar Button Item allocation to this:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文