大佬教程收集整理的这篇文章主要介绍了iphone – 使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];
重要提示:UIAlertView在iOS 8中已被弃用.(请注意,UIAlertViewDelegate也已被弃用.)要在iOS 8及更高版本中创建和管理警报,请改用UIAlertController与优先级的UIAlertControllerStyleAlertStyle.
Please check this out tutorial
.h文件
@interface urViewController : UIViewController <UIAlertViewDelegate> {
.m文件
// Create Alert and set the delegate to listen events UIAlertView *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 handling alert.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 } }
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按钮触发功能按下所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。