我有简单的方法显示带有文本字段的AlertView。显示内存泄漏的仪器。请解释一下。
- (void)method {
NSString *value = [[NSUserDefaults standardUserDefaults] valueForKey:@"key"];
if (value == nil) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alertView.tag = 101;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *txtGroup = [alertView textFieldAtIndex:0];
[txtGroup becomeFirstResponder];
[alertView show];
alertView = nil;
}
}
答案 0 :(得分:0)
您需要将alertView创建为:
static UIAlertView *alertView = nil;
if (!alertView){
alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
}