我正在實施一個操作表。當我按下「確定」按鈕時,做到這些,按「取消」返回。 「ok」按鈕工作正常,但是當我按下「取消」按鈕時,沒有任何反應,它不收回或做任何事情,只是掛在操作單視圖。按取消按鈕不收回
下面是我的代碼:
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
中。