Reputation: 17591
Can I remove a subview with cancelButtonTitle of a UIAlert? Because I write this:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Done!"
message:[@"It's all ok!"]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[self dismissModalViewControllerAnimated:YES];
but this code remove my subview before I push cancelButtonTitle, how can I do?
Upvotes: 1
Views: 745
Reputation: 47241
Yes, implement the UIAlertViewDelegate method alertView:didDismissWithButtonIndex:
and dismiss your view there.
Set the delegate to self first:
...
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Done!"
message:[@"It's all ok!"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
...
Could look like this:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == [alertView cancelButtonIndex]) {
[self dismissModalViewControllerAnimated:YES];
}
}
Upvotes: 2
Reputation: 16540
Set the delegate of the UIAlertView
to self and implement:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
In this method, dismiss the view.
Upvotes: 0