操作表的使用
必须使用Protocol,在类定义的地方定义使用UIActionSheetDelegate协议。
?
@interface testController : UIViewController <UIActionSheetDelegate> {...}
?
在程序里面调用
?
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure?" //标题 delegate:self //此处指定处理按钮按下之后的事件的类,该类必须实现UIActionSheetDelegate协议 cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"OK" otherButtonTitles:@"button1", @"button2", nil]; //可指定多个button,最后一个参数必须为nil[actionSheet showInView:self.view]; //在哪个view里面弹出操作表[actionSheet release]; //一定要release
?
处理按钮事件的方法为实现UIActionSheetDelegate协议的actionSheet方法
?
- (void)actionSheet:(UIActionSheet *)actionSheetdidDismissWithButtonIndex:(NSInteger)buttonIndex{ if( buttonIndex != [actionSheet cancelButtonIndex]){ //code here }}
?