我可以使用哪些入门代码来制作一个带有一个“确定”按钮的简单 UIAlertView?
最佳答案
当您希望显示警报时,请执行以下操作:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ROFL"
message:@"Dee dee doo doo."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
// If you're not using ARC, you will need to release the alert view.
// [alert release];
如果您想在单击按钮时执行某些操作,请实现此委托(delegate)方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked OK
if (buttonIndex == 0) {
// do something here...
}
}
并确保您的委托(delegate)符合 UIAlertViewDelegate
协议(protocol):
@interface YourViewController : UIViewController <UIAlertViewDelegate>
https://stackoverflow.com/questions/4463806/