ios - 添加一个简单的 UIAlertView

我可以使用哪些入门代码来制作一个带有一个“确定”按钮的简单 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/

相关文章:

ios - Swift - 使用哪些类型? NSString 或字符串

iphone - 如何将 UIImage 保存到文件中?

iphone - 代码设计错误 : Certificate identity appearing t

ios - 获取 UITableView 的 Selected 索引

iphone - ${EXECUTABLE_NAME} 和 ${PRODUCT_NAME} 在哪里定

ios - 如何在 xcode 中以编程方式向按钮添加操作

ios - 如何以编程方式检查 iOS 应用程序中是否存在键盘?

ios - 带有两种不同颜色文本的 UILabel

ios - 如何在 UITextView 中禁用复制、剪切、选择、全选

ios - UILabel minimumScaleFactor 是如何工作的?