0

我的弹出框有一个按钮,单击该按钮时,将在主视图控制器中显示一个文本。

这是我的按钮代码:

- (IBAction)print:(UIButton *)sender {
   self.displayText.text= @"Hello World";
}

顺便说一句,我按照这里的教程进行操作。

我试图运行该程序,但当我单击“打印你好世界”按钮时出现此错误:

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[PopoverViewController print:]: unrecognized selector sent to instance 0xe379240”

我认为当它是弹出窗口中的按钮时,情况就不同了。我已经对这个问题采取了一些解决方案(也由遇到同样问题的人发布),但我似乎无法解决它。仍然有错误。希望你能帮助我。

谢谢你。

4

1 回答 1

0

When you set the action for the message, you need to send the message to your View Controller instead of to your Popover.

Which you can't really do when you have them in separate xib's.

There are a few different ways of approaching this, one of which would be to implement a delegate in your popover class, and when you create the popover set the delegate to self (the view controller which created it) and implement the delegate method. Then, when you press the button, it calls a function in your popover class which then calls your delegate's method.

于 2012-09-11T01:29:27.843 回答