1

UIAlertのcancelButtonTitleを使用してサブビューを削除できますか?私がこれを書いているので:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Done!" 
                                                    message:[@"It's all ok!"]
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];

[self dismissModalViewControllerAnimated:YES];

しかし、このコードは、cancelButtonTitleを押す前にサブビューを削除します。どうすればよいですか?

4

2 に答える 2

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];
    }
}
于 2011-04-18T14:22:34.793 に答える
0

のデリゲートUIAlertViewをselfに設定し、以下を実装します。

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

この方法では、ビューを閉じます。

于 2011-04-18T14:23:55.753 に答える