xcode 关闭 UI 操作表 - 崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3840217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dismiss UI action sheet - crash
提问by wallou
I have a "again" ;-) a problem i can't solve.
我有一个“再次”;-) 一个我无法解决的问题。
My app launches on a tableView. When i select a cell, i go to the "detailView". On this view i add two buttons on the toolbar this way :
我的应用程序在 tableView 上启动。当我选择一个单元格时,我会转到“detailView”。在此视图中,我以这种方式在工具栏上添加了两个按钮:
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 115, 44.01)];
// tab where buttons are stored
NSMutableArray* buttons = [[NSMutableArray alloc] init];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(nextEdit)];
UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(popupActionSheet)];
btn.style=UIBarButtonItemStyleBordered;
btn2.style = UIBarButtonItemStyleBordered;
[buttons addObject:btn];
[buttons addObject:btn2];
// add buttons to the toolbar
[tools setItems:buttons animated:YES];
// add buttons within "tools" to the view
UIBarButtonItem *btn3 = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = btn3;
[buttons release];
[btn release];
[btn2 release];
[btn3 release];
[tools release];
Once i click on the trash button i call the method "popupActionSheet" to make "delete confirm" popup appears:
单击垃圾箱按钮后,我调用方法“popupActionSheet”来使“删除确认”弹出窗口出现:
-(void)popupActionSheet {
isActiveSupr=(BOOL)YES;
UIActionSheet *popupQuery = [[UIActionSheet alloc]
initWithTitle:@"Delete ? "
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Confirm"
otherButtonTitles:nil ,nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.tabBarController.view];
[popupQuery release];
}
Then when i click on destructiveButtonTitle:@"Confirm" the "confirm delete" popup dismisses and it calls :
然后,当我点击 corruptionButtonTitle:@"Confirm" 时,"confirm delete" 弹出窗口关闭并调用:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(isActiveSupr==TRUE)
{
if(buttonIndex==0)
{
[self send_requestDelete];
}
}
}
- (void)send_requestDelete:
{
... //nothing to do with popup
[self showActionsheet:@"Demand deleted"];
[self.navigationController popToRootViewControllerAnimated:YES];
... // nothing to do with popup
}
-(void) showActionsheet :(NSString *)msg
{
UIActionSheet *popupQuery = [[UIActionSheet alloc]
initWithTitle:msg
delegate:self
cancelButtonTitle:@"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil ,nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.tabBarController.view];
[popupQuery release];
}
While i go back on my tableViewController the popup("showActionsheet:@"Demand deleted"];") appears.
当我回到我的 tableViewController 时,弹出窗口("showActionsheet:@"Demand deleted"];") 出现。
If i click "OK" my app crashes. If i disable this pop up("showActionsheet") everything is fine.
如果我单击“确定”,我的应用程序就会崩溃。如果我禁用此弹出窗口(“showActionsheet”),一切都很好。
It's like while i go back to the tableView , the popup which was called in "DetailView" doesn't exist anymore.
就像当我回到 tableView 时,在“DetailView”中调用的弹出窗口不再存在。
Thx for the help.
谢谢你的帮助。
采纳答案by Wim Haanstra
First of all, did you put breakpoints on the objc_exception_throw and [NSException raise] exceptions?
首先,你有没有在 objc_exception_throw 和 [NSException raise] 异常上设置断点?
Also because the ActionSheet is added to the subview and directly after that you do this:
也因为 ActionSheet 被添加到子视图中,然后直接执行以下操作:
[self.navigationController popToRootViewControllerAnimated:YES];
The actionsheet is not a modal dialog or anything and it will not block calling other functions in the meanwhile.
操作表不是模态对话框或任何东西,同时它不会阻止调用其他功能。
What could help is if you did something like the following:
如果您执行以下操作,可能会有所帮助:
-(void)popupActionSheet
{
isActiveSupr=(BOOL)YES;
UIActionSheet *popupQuery = [[UIActionSheet alloc]
initWithTitle:@"Delete ? "
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Confirm"
otherButtonTitles:nil ,nil];
popupQuery.tag = 1;
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.tabBarController.view];
[popupQuery release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == 1)
{
if(buttonIndex==0)
{
[self send_requestDelete];
}
}
else if (actionSheet.tag == 2)
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
- (void)send_requestDelete:
{
... //nothing to do with popup
[self showActionsheet:@"Demand deleted"];
... // nothing to do with popup
}
-(void) showActionsheet :(NSString *)msg
{
UIActionSheet *popupQuery = [[UIActionSheet alloc]
initWithTitle:msg
delegate:self
cancelButtonTitle:@"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil ,nil];
popupQuery.tag = 2;
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.tabBarController.view];
[popupQuery release];
}
This way the didDismissWithButtonIndex method know which actionsheet was actually used and what the next action should be.
这样 didDismissWithButtonIndex 方法就知道实际使用了哪个 actionsheet 以及下一个 action 应该是什么。
You should never be removing a view when you are still working on it, like you are.
当您仍在处理视图时,您永远不应该删除它,就像您一样。