【发布时间】:2011-09-08 22:13:53
【问题描述】:
出于某种原因,与我的 UIButton 的交互只能进行一次。我已经通过 IBAction 和带有“addTarget”的 IBOutlet 尝试过。我不知道为什么。
上下文:
基础视图控制器
- (IBAction) button_touched:(id)sender; //<-- Declared here, but not implemented
- (void)userInputReceived:(BOOL)bSuccess; //<-- Declared here, but not implemented
ViewController1 : BaseViewController
- (IBAction) button_touched:(id)sender; //<-- Implemented here
- (void)userInputReceived:(BOOL)bSuccess; //<-- Implemented here
另外,这是我尝试“addTarget”的地方,但这也不起作用(第一次触摸有效,但第二次无效)
在 ViewController1 (vc1) 的“button_touched”方法中,我像这样调用另一个类:
[someOtherClassObject doSomethingWithMyView:self];
该类只是弹出一个消息框,获取用户输入,然后回调视图控制器:
(在 SomeOtherClass 内):
-(void)doSomethingWithMyView:(BaseViewController*)vc
{
// Do Something
[vc userInputReceived:TRUE];
}
一旦此工作流程执行一次,按钮触摸就不再调用“button_touch”方法。无论我做什么,我都无法再次调用它。
在一个流行的 BBS 论坛上的一个帖子中,有人提到这样的问题可能是由于没有您认为自己拥有的对象 (vc1),而是它的另一个实例。所以,我在很多地方记录了类似 NSLog("instance: %p", self) 的实例,而且它总是一样的。
非常感谢任何想法。这很令人沮丧。
【问题讨论】:
-
你能从你的 button_touched: 方法中发布你所有的代码吗?另外,您是如何将您的按钮连接到 IBAction 的?您需要什么样的触摸方式?
标签: iphone ios uibutton target ibaction