【发布时间】:2010-08-23 07:59:29
【问题描述】:
我正在实施一个行动表。当我按“确定”按钮时,执行这些操作,按“取消”返回。 “确定”按钮工作正常,但是当我按下“取消”按钮时,什么也没有发生,它不会缩回或做任何事情,只是挂在操作表视图上。
下面是我的代码:
在导航栏上创建按钮:
UIBarButtonItem *clearButton = [[[UIBarButtonItem alloc] initWithTitle:@"Clear History"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(ClearHistoryAction:)] autorelease];
self.navigationItem.leftBarButtonItem = clearButton;
当我单击并启动操作表时:
- (IBAction)ClearHistoryAction:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Clear History?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"OK"
otherButtonTitles:nil];
// use the same style as the nav bar
actionSheet.actionSheetStyle = self.navigationController.navigationBar.barStyle;
[actionSheet showInView:self.view];
[actionSheet release];
}
如果选择确定,请执行以下操作:
- (void)actionSheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger) buttonIndex
{
if (!buttonIndex == [actionSheet cancelButtonIndex])
{
//do what i want here!
}
}
在头文件中,UIActionSheetDelegate包含在@interface中。
【问题讨论】:
标签: iphone objective-c cocoa-touch ios