iphone - 如何从UIAlertView运行方法

标签 iphone objective-c ios uialertview

当用户触摸以下[User logOut];中的将我注销按钮时,我希望运行此方法UIAlertView

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logged in!" message:@"Logged in to App!" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:@"Log me out", nil];
        [alert show];
        [alert release];

我将如何去做? “确定”用于取消按钮。我只需要其他按钮/方法即可工作。

谢谢你的帮助

最佳答案

你可以做类似的事情;

- (void)AlertConfirm
{
    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setTitle:@"Confirm"];
    [alert setMessage:@"Log out?"];
    [alert setDelegate:self];
    [alert addButtonWithTitle:@"Yes"];
    [alert addButtonWithTitle:@"No"];
    [alert show];
    [alert release];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        // Yes, do something
    }
    else if (buttonIndex == 1)
    {
        // No
    }
}

祝好运,
内森

关于iphone - 如何从UIAlertView运行方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10553917/

相关文章:

iphone - iOS阵列初始化错误

iphone - 从应用程序内更改当前位置

css - 附件按钮在 OS mobile 中不起作用

iphone - 在头文件中使用变量和常量定义进行本地化

iphone - iOS5 显示MIME消息

ios - 在 Objective C(iOS 应用程序)中请求 WCF Web 服务时收到 SOAP 错误

iphone - 如何在 ARC 下创建不泄漏的 CFUUID NSString?

objective-c - 从 textField 获取 int

ios sendAsynchronousRequest定时器

c++ - Objective C 对象作为 C++ 类中的实例变量