我可以使用UIAlert的cancelButtonTitle删除子视图吗?因为我写这个:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Done!"
message:[@"It's all ok!"]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[self dismissModalViewControllerAnimated:YES];
但是这个代码在推送cancelButtonTitle之前删除了我的子视图,我该怎么办?
答案 0 :(得分:2)
是的,实施UIAlertViewDelegate方法alertView:didDismissWithButtonIndex:
并在那里解除您的观点。
将委托设置为自己:
...
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Done!"
message:[@"It's all ok!"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
...
看起来像这样:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == [alertView cancelButtonIndex]) {
[self dismissModalViewControllerAnimated:YES];
}
}
答案 1 :(得分:0)
将UIAlertView
的委托设置为self并实现:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
在此方法中,关闭视图。