`

iPhone开发之UIActionSheet的使用

 
阅读更多

UIActionSheet是iOS开发中实现警告框的重要的类,在很多情况下都要用到,先来一睹其芳容:

实现步骤如下:

一、为了让控制器类充当操作表的委托,控制器类需要遵从UIActionSheetDelegate协议。

@interface UIActionSheetDemoViewController : UIViewController <UIActionSheetDelegate>{
}

二、生成UIActionSheet并显示。

UIActionSheet *actionSheet = [[UIActionSheet alloc] 
							  initWithTitle:@"Are you sure?"
							  delegate:self 
							  cancelButtonTitle:@"No way!" 
							  destructiveButtonTitle:@"Yes, I'm sure." 
							  otherButtonTitles:@"Button One", @"Button Two", nil];

[actionSheet showInView:self.view];
[actionSheet release];

三、点击按钮后的事件。

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
 NSLog(@"%i", buttonIndex);
 if (buttonIndex == actionSheet.cancelButtonIndex) {
  return;
 }
 switch (buttonIndex) {
  case 0: {
   NSLog(@"Item 1 Selected");
   break;
  }
  case 1: {
   NSLog(@"Item 2 Selected");
   break;
  }
  case 2: {
   NSLog(@"Item 3 Selected");
   break;
  }
 }
}

点击此处下载示例。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics