我可以用什么启动代码来创建一个简单的UIAlertView,上面有一个"OK"按钮?

推荐答案

当您希望显示alert 时,请执行以下操作:

    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];

如果要在单击按钮时执行某些操作,请实现此委托方法:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    // the user clicked OK
    if (buttonIndex == 0) {
        // do something here...
    }
}

并确保您的代表符合UIAlertViewDelegate协议:

@interface YourViewController : UIViewController <UIAlertViewDelegate> 

Ios相关问答推荐

滚动时突出显示工具栏项目

如何在wiftUI中管理导航栈?

Xamarin Forms CustomPin iOS Render

在视图上执行手势会阻止相机操作

为什么iOS委派在KMM中不能正常工作?

无法向委托发送数据

SwiftUI:.toolbar 不适用于 UITextView

为什么IOS多行文本输入在React原生纸张对话框中无法正常工作?

在 React Native iOS 中加载多个 JS 包

Swift中是否有一种方法可以为可选属性创建一个计算(computed)属性

在Xcode 15中为具有@Binding的视图创建SwiftUI #预览的方法

在自定义 ButtonStyle 中修改形状 colored颜色

Flutter firebase_auth 中的无效应用程序凭据/令牌不匹配

Swiftui为什么在点击第二行之前背景不起作用

如何将单个按钮传递到自定义 ConfirmationDialog

通过 tuist/XcodeProj 以编程方式将文件添加到本机目标

如何使用 Swift 文档注释

ARKit vs. ARCore vs. Vuforia vs. D'Fusion Mobile vs. Layar SDK

Swift 中的日期到毫秒和回溯到日期

UITableView 中的圆形 UIImageView 没有性能影响?