我有一个名为FlightRecorder
和BookmarkTableViewController
的课程。现在,我将介绍BookmarkTableViewController
。而现在我正在解雇那个视图控制器。这是代码的样子:
[self dismissViewControllerAnimated:YES completion:^{
FlightRecorder *fl = [[FlightRecorder alloc] init];
[fl endBookmarkProcessWithBookmarkCollection: dict];
}
在选择表格视图单元格后调用此方法。因此,FlightRecorder
有一个名为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
,警报视图的代表,是零或过度释放或类似的东西。所以我想,也许在视图加载之前调用该方法,即使在明显完成时调用它(BookmarksTableViewController
中的完成块)。
所以我决定将NSLog
放在viewDidLoad
和endBookmarkProcessWithBookmarkCollection:
中,但viewDidLoad
首先被调用,所以我是不确定问题在哪里。
感谢您的帮助!
答案 0 :(得分:1)
该块已完成执行且f1已超出范围并且在您点击按钮之前已被解除分配。我不熟悉你的应用程序的架构,但你需要在等待点击时找到该对象的所有者。