MCKapur
MCKapur

Reputation: 9157

UIAlertView crash on click - Using ARC

I have a class called FlightRecorder and BookmarkTableViewController. Now, I am presenting the BookmarkTableViewController. And now I am dismissing that view controller. Here is what the code looks like:

    [self dismissViewControllerAnimated:YES completion:^{

    FlightRecorder *fl = [[FlightRecorder alloc] init];
    [fl endBookmarkProcessWithBookmarkCollection: dict];

    }

This is getting called after selection of a table view cell. So, FlightRecorder has a method called endBookmarkProcessWithBookmarkCollection: where you pass on an NSDictionary which looks like this:

- (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];

}

So as you can see, I use the dictionary and some other variables to piece together the message of an alert view! The alert view has two buttons, Cancel and Add. But the problem is that when you press either of them, they both crash, and the clickedButtonAtIndex: delegate method is not called. I have not had this experience with any other alert views in the exact same view controller.

I looked at some other questions of similar manner, but they're solutions were using ARC. Bottomline they said that self, the delegate of the alert view, is nil or overreleased or something like that. So I thought, maybe that method is getting called before the view loads, even though it is called on apparent completion (the completion block in BookmarksTableViewController).

So I decided to put NSLog's in both viewDidLoad and endBookmarkProcessWithBookmarkCollection:, but viewDidLoad is getting called first, so I am not sure where the problem is.

Thanks for any help!

Upvotes: 0

Views: 374

Answers (1)

Carl Veazey
Carl Veazey

Reputation: 18363

That block has finished executing and f1 has gone out of scope and been deallocated well before you tap the buttons. I'm not familiar with the architecture of your app but you'll need to find an owner for that object while waiting for the tap.

Upvotes: 1

Related Questions