肯定不是先release 了,再调用的情况
实在是无法理解,随即把代码copy到一个干净的工程里跑了下,完全没有问题,然后突然想起来,只有主线程才有权限更改UI,这个UIAlertView会不会也是属于UI的更新呢,于是调用方法 performSelectorOnMainThread 方法,去主线程掉用显示UIAlertView的方法,果然好了。
记录下来,怕以后忘了。
下面是代码,这个弹出的UIAlertView是会自动关掉的
- (void) showAutoClearMessage:(NSString*) message { if ([NSRunLoop currentRunLoop] != [NSRunLoop mainRunLoop]) { NSLog(@"<< perform in main thread>>"); [self performSelectorOnMainThread:@selector(showAutoClearMessage:) withObject:message waitUntilDone:NO]; return; } autoClearAlert = [[UIAlertView alloc] initWithTitle:@"" message:message delegate:self cancelButtonTitle:nil otherButtonTitles: nil]; [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector: @selector(performDismiss:) userInfo:nil repeats:NO]; [autoClearAlert show]; } - (void) performDismiss: (NSTimer *)timer { [autoClearAlert dismissWithClickedButtonIndex:0 animated:NO]; [autoClearAlert release]; autoClearAlert = NULL; }