Ios 点击按钮时UIAlertView崩溃
我在普通的视野中遇到了一些麻烦 场景:我的应用程序能够导入自己的数据类型进行备份/恢复。on-application:openURL:sourceApplication:annotation:我创建我的导入器类并启动导入操作本身。在实际导入开始之前,应询问用户是否要删除/覆盖其旧数据库 UIAlertView显示得很好。当我按下两个按钮中的一个“是”和“否”时,应用程序在控制台上没有任何信息的情况下崩溃。我正在主线程上提高警报。它是这样创建的:Ios 点击按钮时UIAlertView崩溃,ios,delegates,crash,uialertview,Ios,Delegates,Crash,Uialertview,我在普通的视野中遇到了一些麻烦 场景:我的应用程序能够导入自己的数据类型进行备份/恢复。on-application:openURL:sourceApplication:annotation:我创建我的导入器类并启动导入操作本身。在实际导入开始之前,应询问用户是否要删除/覆盖其旧数据库 UIAlertView显示得很好。当我按下两个按钮中的一个“是”和“否”时,应用程序在控制台上没有任何信息的情况下崩溃。我正在主线程上提高警报。它是这样创建的: UIAlertView *dataAvailabl
UIAlertView *dataAvailableAlert = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMessage
delegate:self
cancelButtonTitle:noButtonTitle
otherButtonTitles:yesButtonTitle, nil];
[dataAvailableAlert show];
我的类采用UIAlertViewDelegate并实现-alertView:ClickedButtonIndex:。后者根本不会被呼叫。更新:我正在使用ARC。回溯:
* thread #1: tid = 0x1c03, 0x01bc809f libobjc.A.dylib`objc_msgSend + 19, stop reason = EXC_BAD_ACCESS (code=1, address=0xfd940000)
frame #0: 0x01bc809f libobjc.A.dylib`objc_msgSend + 19
frame #1: 0x00eee0bc UIKit`-[UIAlertView(Private) _buttonClicked:] + 294
frame #2: 0x01bca705 libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 77
frame #3: 0x00afe2c0 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
frame #4: 0x00afe258 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
frame #5: 0x00bbf021 UIKit`-[UIControl sendAction:to:forEvent:] + 66
frame #6: 0x00bbf57f UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 578
frame #7: 0x00bbe6e8 UIKit`-[UIControl touchesEnded:withEvent:] + 546
frame #8: 0x00b2dcef UIKit`-[UIWindow _sendTouchesForEvent:] + 846
frame #9: 0x00b2df02 UIKit`-[UIWindow sendEvent:] + 273
frame #10: 0x00b0bd4a UIKit`-[UIApplication sendEvent:] + 436
frame #11: 0x00afd698 UIKit`_UIApplicationHandleEvent + 9874
frame #12: 0x02779df9 GraphicsServices`_PurpleEventCallback + 339
frame #13: 0x02779ad0 GraphicsServices`PurpleEventCallback + 46
frame #14: 0x024b5bf5 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
+ 53
frame #15: 0x024b5962 CoreFoundation`__CFRunLoopDoSource1 + 146
frame #16: 0x024e6bb6 CoreFoundation`__CFRunLoopRun + 2118
frame #17: 0x024e5f44 CoreFoundation`CFRunLoopRunSpecific + 276
frame #18: 0x024e5e1b CoreFoundation`CFRunLoopRunInMode + 123
frame #19: 0x027787e3 GraphicsServices`GSEventRunModal + 88
frame #20: 0x02778668 GraphicsServices`GSEventRun + 104
frame #21: 0x00afaffc UIKit`UIApplicationMain + 1211
frame #22: 0x00002e8d Foo`main(argc=1, argv=0xbffff61c) + 141 at main.m:16
frame #23: 0x00002db5 Foo`start + 53
你知道这是怎么回事吗
谢谢
–f
更新:根据整个班级的要求
@implementation NEADatabaseImporter
- (id)initWithDictionary:(NSDictionary *)importDictionary {
self = [super init];
if (self) {
_importDictionary = importDictionary;
}
return self;
}
- (void)startImport {
// check if the current database already has some data in it
BOOL dataCreated = ([[NEADataAccessor groups] count] > 1);
// if so ask the user if he wants to delete the old data
if (dataCreated) {
// prepare variables for better reading
NSString *alertTitle = NSLocalizedString(@"REPLACE_DATABASE_TITLE", @"The title for the alert asking the user to let the app replace his database upon import.");
NSString *alertMessage = NSLocalizedString(@"REPLACE_DATABASE_MESSAGE", @"The message the alert displays when asking the user for permission to replace the database upon import.");
NSString *yesButtonTitle = NSLocalizedString(@"YES", @"Yes");
NSString *noButtonTitle = NSLocalizedString(@"NO", @"No");
UIAlertView *dataAvailableAlert = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMessage
delegate:self
cancelButtonTitle:noButtonTitle
otherButtonTitles:yesButtonTitle, nil];
[dataAvailableAlert show];
} else {
// if there was no data yet we can directly invoke the import
[self removeDatabase];
[self readDatabaseImportDictionary];
}
}
- (void)removeDatabase {
NEAAppDelegate *delegate = (NEAAppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate databaseManager] clearStores];
}
- (void)readDatabaseImportDictionary {
if (![self importDictionary]) return;
// read it here
NEAAppDelegate *delegate = (NEAAppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate currentProfile] readDataDictionary:[self importDictionary]];
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSInteger yesIndex = 1;
if (buttonIndex == yesIndex) {
// go ahead and replace the database
[self removeDatabase];
[self readDatabaseImportDictionary];
} else {
// cancel the import
NSLog(@"import of dictionary canceled: %@", [self importDictionary]);
}
}
@end
更新:shannoga是对的。看来我的NeadabaseImporter发布得太早了。当我使它成为调用类的强属性时,它工作得很好。但让一切都成为强大的财产并不是解决办法,不是吗?使用ARC存储局部变量的正确方法是什么?这只是猜测,但几个月前我遇到了同样的问题 我的问题是,警报视图的代理在显示后被释放,因此当警报被解除时,它会向其代理发送一条消息,但它不再存在 另一个选项是,显示警报视图的viewController在显示后被释放 因此,基本上要检查提示代表的身份是否在提示后未被释放
希望能有所帮助这只是猜测,但几个月前我也遇到了同样的问题 我的问题是,警报视图的代理在显示后被释放,因此当警报被解除时,它会向其代理发送一条消息,但它不再存在 另一个选项是,显示警报视图的viewController在显示后被释放 因此,基本上要检查提示代表的身份是否在提示后未被释放
希望这会有帮助哦,是的。我使用的是ARC。你能补充一些关于崩溃本身的信息吗?添加异常断点并查看异常是什么。确定。它说线程1:EXC_BAD_访问代码2,地址=0xb。对我来说,它似乎试图称之为释放。正当但是,嗯,什么?发生这种情况时,日志中有什么相关信息吗?我得到的只是回溯。我把它添加到上面的描述中。哦,是的。我使用的是ARC。你能补充一些关于崩溃本身的信息吗?添加异常断点并查看异常是什么。确定。它说线程1:EXC_BAD_访问代码2,地址=0xb。对我来说,它似乎试图称之为释放。正当但是,嗯,什么?发生这种情况时,日志中有什么相关信息吗?我得到的只是回溯。我把它添加到上面的描述中。这就是我的想法。你是对的。当我使NeadabaseImporter成为调用类的强属性时,它工作得很好。但让一切都成为强大的财产并不是解决办法,不是吗?使用ARC强存储局部变量的正确方法是什么?你可以使用_弱将弱自我传递给你的Alerter,这就是我的想法。你是对的。当我使NeadabaseImporter成为调用类的强属性时,它工作得很好。但让一切都成为强大的财产并不是解决办法,不是吗?使用ARC强存储局部变量的正确方法是什么?您可以使用_弱将弱自我传递给您的警报