iphone – 使UIAlertView按钮触发功能按下

iphone – 使UIAlertView按钮触发功能按下,第1张

概述目前我正在使用以下代码来呈现UIAlertView: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Today's Entry Complete" message:@"Press OK to submit your data!" de 目前我正在使用以下代码来呈现UIAlertVIEw:

UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Today's Entry Complete"                        message:@"Press OK to submit your data!"                        delegate:nil               cancelbuttonTitle:@"OK"               otherbuttonTitles: nil];    [alert show];    [alert release];

如何得到它,以便当按下“OK”时,它会触发一个函数,例如 – (voID)submitData

解决方法 注意:

重要提示:UIAlertVIEw在iOS 8中已被弃用.(请注意,UIAlertVIEwDelegate也已被弃用.)要在iOS 8及更高版本中创建和管理警报,请改用UIAlertController与优先级的UIAlertControllerStyleAlertStyle.

Please check this out tutorial

“deprecated” means???

ObjectvIE C

.h文件

@interface urVIEwController : UIVIEwController <UIAlertVIEwDelegate> {

.m文件

// Create Alert and set the delegate to Listen eventsUIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Today's Entry Complete"                                                message:@"Press OK to submit your data!"                                               delegate:self                                      cancelbuttonTitle:nil                                      otherbuttonTitles:@"OK",nil];// Set the tag to alert unique among the other alerts.// So that you can find out later,which alert we are handlingalert.tag = 100;[alert show];//[alert release];-(voID) alertVIEw:(UIAlertVIEw *)alertVIEw clickedbuttonAtIndex:(NSInteger)buttonIndex{    // Is this my Alert VIEw?    if (alertVIEw.tag == 100) {        //Yes    // You need to compare 'buttonIndex' & 0 to other value(1,2,3) if u have more buttons.    // Then u can check which button was pressed.        if (buttonIndex == 0) {// 1st Other button            [self submitData];        }        else if (buttonIndex == 1) {// 2nd Other button        }    }    else {     //No        // Other Alert VIEw    }}

Swift

Swifty的方法是使用新的UIAlertController和closure:

// Create the alert controller    let alertController = UIAlertController(Title: "Title",message: "Message",preferredStyle: .Alert)    // Create the actions    let okAction = UIAlertAction(Title: "OK",style: UIAlertActionStyle.Default) {        UIAlertAction in        NSLog("OK pressed")    }    let cancelAction = UIAlertAction(Title: "Cancel",style: UIAlertActionStyle.Cancel) {        UIAlertAction in        NSLog("Cancel pressed")    }    // Add the actions    alertController.addAction(okAction)    alertController.addAction(cancelAction)    // Present the controller    self.presentVIEwController(alertController,animated: true,completion: nil)
总结

以上是内存溢出为你收集整理的iphone – 使UIAlertView按钮触发功能按下全部内容,希望文章能够帮你解决iphone – 使UIAlertView按钮触发功能按下所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1061749.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存