在iphone程序中有一些操作需要提醒用户确实要进行,确保用户因手误删除重要数据,下面是一种警告窗口:
实现发放很简单:
- 在相应的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;
}
} - 在相应的函数中调用showActionSheetButtonPressed即可。