我的 BarButton 中的错误
我的代码中有一个错误,但我似乎找不到它!我以编程方式创建了一个名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的添加选择器末尾有一个冒号,这意味着它正在尝试使用带有参数的添加方法,但您的添加方法不需要参数对象。您需要通过将 Bar Button Item 分配更改为以下内容来从选择器中删除冒号:
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: