我正在实现一份行动表。当我按“确定”按钮时,执行这些操作,按“取消”返回。 “确定”按钮工作正常,但是当我按下“取消”按钮时,没有任何反应,它不会缩回或执行任何操作,只是卡在操作 TableView 上。
下面是我的代码:
在导航栏上创建按钮:
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
中。
最佳答案
迟到了,但可能的解释是:
Seems to be an issue with the tabbar. If you call UIActionSheet's
[sheet showInView:self.view]
from a view controller that is a child of a UITabViewController, then the hit testing on the cancel button fails in that portion of the UIActionSheet that lies above the tabbar's view.
如果您改为传入 UITabBarController 的 View ,则 UIActionSheet 将按预期运行。
[sheet showInView:self.parentViewController.tabBarController.view];
关于iphone - 按取消按钮不会缩回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3545657/