【发布时间】:2012-01-05 16:49:29
【问题描述】:
在一个方法中,我想在 n 秒后调用一个方法:
self.toolBarState = [NSNumber numberWithInt:1];
[self changeButtonNames];
[self drawMap];
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:2];
我想在 drawMap 完成 2 秒后显示操作表。当我使用这个 performSelector 时,它永远不会调用。
如果我只输入 [self showActionSheet];,它就可以正常工作。 performSelector 没有进行调用有什么原因吗?
编辑:在我的代码的另一部分,我进行了相同的调用并且它有效:
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = (id) self;
[HUD showWhileExecuting:@selector(drawMap) onTarget:self withObject:nil animated:YES];
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:6];
这里,showActionSheet 在 drawMap 完成 6 秒后被调用。我猜我还不明白的线程正在发生一些事情......
EDIT2:
-(void)showActionSheet
{
InspectAppDelegate *dataCenter = (InspectAppDelegate *) [[UIApplication sharedApplication] delegate];
if (dataCenter.fieldIDToPass == nil)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Selected Boundary Options" delegate:(id) self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Analyze a Field",@"Retrieve Saved Analysi", @"Geotag Photos", @"Refresh the map",nil];
actionSheet.tag = 0;
[actionSheet showInView:self.view];
}
else
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Selected Boundary Options" delegate:(id) self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Analyze a Field",@"Retrieve Saved Analysi", @"Geotag Photos", @"Attribute the Field", @"Refresh the map",nil];
actionSheet.tag = 0;
[actionSheet showInView:self.view];
}
}
EDIT3:
好的,那么方法调用的进度是:
-(void) foundDoubleTap:(UITapGestureRecognizer *) recognizer
{
[HUD showWhileExecuting:@selector(select) onTarget:self withObject:nil animated:YES];
}
-(void) select
{
[self changeButtonNames];
[self drawMap];
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:2];
}
showActionSheet 永远不会被调用。就像我说的,我很确定这是一个线程问题。如果用 [self showActionSheet] 调用它,它将运行。 =/
【问题讨论】:
-
你能把showActionSheet方法的代码贴出来吗?
标签: iphone objective-c ios