如何给 barbuttonitem 动作?

2023-12-22

当单击 UIToolBar 上的完成按钮时,我想调出“TableViewController”的 .nib。但下面不允许单击打开新视图。我该如何纠正这个问题?请告诉我哪里出了问题,应该更换什么以及原因。

//Here's the selector in my overlay. 
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed)];

//Here's how I made my action. Btw, the uitoolbar has no nib, it's an overlay on the
//(camera mode).

-(void)doneButtonPressed {
TableViewController *tableView = [[TableViewController alloc]
initWithNibName:@"TableViewController" bundle:nil];
tableView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tableView animated:YES];
}


//Yet nothing happens when I click on my done button on my overlay. And I've made sure
//   i've imported .h frameworks correctly too.

假设您要从 UItoolbar 覆盖层上的 barbuttonitem 中调出笔尖。你会怎么做?

有人告诉我,要使其正常工作,我必须添加 [barButtonItem addTarget:self action:@selector(doneButtonPressed) forControlEvents:UIControl Event TouchUpInside]; 。

但如果我添加它,我会得到这个:

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone addTarget:self action:@selector(doneButtonPressed)
forControlEvents:UIControlEventTouchUpInside];

这导致我收到错误消息“instance method' - initWithBarButtonSystemItem:target:action:forControlEvents:' not find (return type defaults to 'id')”

除了我在这里编写的代码之外,请向我展示解决方案,而不是仅向我展示正确的添加剂。


如果您使用的是 XCode 4,您只需按住 Ctrl 键并拖动BarButtonItem,到您的 .h 文件,您可以从那里自动创建 IB 操作。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何给 barbuttonitem 动作? 的相关文章

随机推荐