iphone通过UIActionSheetDelegate实现警告

来源:互联网 发布:大数据 股票预测模型 编辑:程序博客网 时间:2024/05/19 00:16

在iphone程序中有一些操作需要提醒用户确实要进行,确保用户因手误删除重要数据,下面是一种警告窗口:

IMG_0029

 

实现发放很简单:

  • 在相应的controller的.h中添加UIActionSheetDelegate协议。如:
  • @interface Stage5ViewController : UIViewController
    <UIActionSheetDelegate>

  • 在.m中添加相应的方法即可:
  • -(IBAction) showActionSheetButtonPressed:(id) sender
    {
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
    initWithTitle:@”Congratulation. You have completed the elimination diet and food challenge test. Do you want to share your progress with friends?”
    delegate:self
    cancelButtonTitle:@”Cancel”
    destructiveButtonTitle:nil
    otherButtonTitles:@”Facebook”,@”Twitter”,nil ];
    [actionSheet showInView:self.view];//参数指显示UIActionSheet的parent。
    [actionSheet release];
    }
    -(void) actionSheet : (UIActionSheet *) actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex
    {
    switch (buttonIndex) {
    case 0:
    NSLog(@”facebook”);
    break;
    case 1:
    NSLog(@”twitter”);
    break;
    default:
    break;
    }
    }

原创粉丝点击