【发布时间】:2013-02-26 08:33:32
【问题描述】:
我有一个 IBAction,它看起来像这样。
- (IBAction) onPressed: (id) sender {
[self openMyDelegateToSeeIfIAmReady];
if (AmIReady == YES)
{
[self doMyWork];
}
}
目前,这不起作用。 AmIReady 是一个布尔值,它在 openMyDelegateToSeeIfIAmReady 中更改为 YES。问题是,在AmIReady 变为YES 之前,这段代码
if (AmIReady == YES)
{
[self doMyWork];
}
被调用,doMyWork 永远不会被调用。我怎样才能让这个方法等到它完成[self openMyDelegateToSeeIfIAmReady]?
编辑:
这是我在openMyDelegateToSeeIfIAmReady 中的内容
- (void) openMyDelegateToSeeIfIAmReady
{
MyViewController *mvc = [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];
mvc.delegate = self;
[self presentModalViewController:mvc animated:YES];
[mvc release];
amIReady = YES;
}
同样在这个委托(MyViewCrontroller)中,它需要用户的输入。如果输入了用户输入,我需要运行doMyWork。
【问题讨论】:
-
它已经在等待了。
-
如果您没有在另一个线程上运行该方法,那么该函数将在到达 if 语句之前完成
-
它应该等待;无论如何,你能发布
openMyDelegateToSeeIfIAmReady的代码吗? -
@rocky:+1 你是对的,我在为 osx 开发时遇到过很多次类似的问题,因为你没有提到你的目标(osx 或 ios)。
-
我们需要查看
openMyDelegateToSeeIfIAmReady的来源才能回答这个问题。
标签: objective-c ios5.1