0

我有一个带有多个按钮的 UIAlertView。是否可以灰显并禁用按钮?我希望按钮是可见的,但很清楚它不能被按下。任何建议表示赞赏。

4

2 回答 2

1

Make sure that you have enabled the current VC as implementing the <UIAlertViewDelegate> protocol, and then in your VC you could do the following:

- (void)viewDidAppear:(BOOL)animated {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"This is an alert view" delegate:nil cancelButtonTitle:@"Cancel!" otherButtonTitles:@"Off", @"On", nil];
    alert.delegate = self;
    [alert show];
}


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

// Other UIAlertViewDelegate methods...

Now why you would want to show a UIAlertView with a button which didn't have any functionality is a whole different question... :)

于 2013-08-03T02:46:03.687 回答
0

I hear of lots of people subclassing UIAlertView, but then I read this comment on Apple's UIAlertView Class Reference page:

Subclassing Notes

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

i.e. people should not be attempting to modify the elements or behavior of UIAlertView. It's likely that behavior can change in later versions of iOS (e.g. iOS 8 or iOS 7.1 or whatever), breaking their various modifications to UIAlertView.

Anyways, to answer your question: why not try creating your own UIView that you can add as UIAlertView-like subview on top of any of your views? That way, you'd have easy control over both the buttons and their behavior.

于 2013-08-03T02:38:41.583 回答