UIAlertView alertView.cancelButtonIndex = -1;不工作

时间:2013-11-28 18:42:32

标签: ios7 uialertview

我正在尝试创建一个没有取消按钮的AlertView。

这是我尝试过的代码:

    alertView.cancelButtonIndex = -1;

它似乎不适用于iOS 7。

有什么想法吗?

谢谢,

1 个答案:

答案 0 :(得分:0)

1)使用此代码时,按“执行某些按钮”可以执行某些操作,但不会导致alertView隐藏

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Title" message:@"The message."  delegate:self cancelButtonTitle:nil otherButtonTitles: @"Do something", nil] show];

#pragma mark - UIAlertViewDelegate

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView {
    return NO; 
}

2)使用此代码时,alertView上没有任何按钮(我认为这是您实际需要的

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Title" message:@"The message."  delegate:self cancelButtonTitle:nil otherButtonTitles:nil] show];