Ios 如何给予巴布托效应?

Ios 如何给予巴布托效应?,ios,Ios,当单击UIToolBar上的“完成”按钮时,我想打开“TableViewController”的.nib。但下面的内容不允许单击打开新视图。我如何纠正这一点?请告诉我哪里出了问题,应该更换什么,为什么 //Here's the selector in my overlay. UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone t

当单击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覆盖层上的Barbuttonite中取出笔尖。你会怎么做

我被告知要使其正常工作,我必须添加[barButtonItem addTarget:self action:@selector(doneButtonPressed)forControlEvents:UIControlEventTouchUpInside]

但如果我加上它,我会得到:

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone addTarget:self action:@selector(doneButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
这导致我在读取“实例方法”-initWithBarButtonSystemItem:target:action:forControlEvents:'未找到(返回类型默认为'id')”时出错


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

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

一个
UIBarButtonItem
遵循默认的
UIControlEventTouchUpInside
,您无法设置它。Xcode应该自动建议分配它的方法,但正确的代码是:

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed)];
注意,ControlEvents没有

请尝试以下更改:

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

-(void)doneButtonPressed:(id)sender
{
}
向目标传递启动操作的对象(即UIBarButtonItem本身)


其次,在doneButtonPressed函数中设置断点。例如,如果tableView被设置为nil,那么您将不会看到任何事情发生。i、 e.实例化此视图控制器可能有问题。

我以编程方式创建了barbuttonitem,因为它所在的工具栏是以编程方式创建的,因此使用IB是不可行的。因此,如果void方法即使在我按照您的建议进行了更正后仍没有执行切换到新视图,我应该怀疑什么呢,设置断点并查看是否正在调用该方法。另外:
[self-presentViewController:tableView动画:是完成:无]