几秒钟后,我正在使用以下代码隐藏 UILabel 。不幸的是,如果用户在 NSInvocation 过程中关闭视图,则应用程序崩溃
- (void)showStatusBarwithText:(NSString*)text{
lblNotification.hidden=NO;
NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:[lblNotification methodSignatureForSelector:@selector(setHidden:)]];
[invoc setTarget:lblNotification];
[invoc setSelector:@selector(setHidden:)];
lblNotification.text=text;
BOOL yes = YES;
[invoc setArgument:&yes atIndex:2];
[invoc performSelector:@selector(invoke) withObject:nil afterDelay:1];
}
这就是错误
*** -[UILabel setHidden:]: message sent to deallocated instance 0x1a8106d0
我该如何解决?我试过使用
[NSObject cancelPreviousPerformRequestsWithTarget:lblNotification]
在中,- (void)viewDidDisappear:(BOOL)animated
但它不起作用。