[英]UIAlertView crash on click - Using ARC
我有一個叫做FlightRecorder
和BookmarkTableViewController
的類。 現在,我介紹BookmarkTableViewController
。 現在,我解雇了該視圖控制器。 代碼如下所示:
[self dismissViewControllerAnimated:YES completion:^{
FlightRecorder *fl = [[FlightRecorder alloc] init];
[fl endBookmarkProcessWithBookmarkCollection: dict];
}
選擇表視圖單元格后將調用此方法。 因此, FlightRecorder
有一個名為endBookmarkProcessWithBookmarkCollection:
的方法endBookmarkProcessWithBookmarkCollection:
您可以在其中傳遞如下所示的NSDictionary
:
- (void)endBookmarkProcessWithBookmarkCollection: (NSDictionary *)dict {
NSString *compiledText = @"Random Airline";
NSString *string = [NSString stringWithFormat: @"\nMiles: %.2f\nFlight: %@\nDate: %@", [[dict objectForKey: @"miles"] floatValue], compiledText, [[NSUserDefaults standardUserDefaults] objectForKey:@"tempD"]];
self.bkBookmarkAlertView = [[UIAlertView alloc] initWithTitle:@"Confirmation" message:string delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
[bkBookmarkAlertView show];
}
如您所見,我使用字典和其他一些變量來組合警報視圖的消息! 警報視圖有兩個按鈕,“取消”和“添加”。 但是問題在於,當您按下它們中的任何一個時,它們都會崩潰,並且不會調用clickedButtonAtIndex:
委托方法。 我沒有在完全相同的視圖控制器中使用任何其他警報視圖的經驗。
我看了一些其他類似問題,但它們是使用ARC的解決方案。 他們的底線是,警報視圖的代表self
或為nil或被過度釋放。 因此,我認為,即使在表觀完成時調用了該方法,也可能在視圖加載之前調用了該方法( BookmarksTableViewController
的完成塊)。
所以,我決定把NSLog
的兩個viewDidLoad
和endBookmarkProcessWithBookmarkCollection:
但viewDidLoad
被越來越第一調用,所以我不知道問題出在哪里。
謝謝你的幫助!
在您點擊按鈕之前,該塊已完成執行,並且f1超出范圍並已重新分配。 我對您的應用程序的體系結構不熟悉,但是您需要在等待輕按的同時找到該對象的所有者。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.