关闭UI操作表 - 崩溃

时间:2010-10-01 14:41:52

标签: iphone objective-c xcode crash uiactionsheet

我有一个“再次”;-)一个我无法解决的问题。

我的应用程序在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];

一旦我点击垃圾按钮,我就会调用方法“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];
}

然后当我点击destructiveButtonTitle:@“确认”时,“确认删除”弹出窗口解除并调用:

- (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];
}

当我回到我的tableViewController时,会出现弹出窗口(“showActionsheet:@”Demand deleted“];”)。

如果我点击“确定”我的应用程序崩溃了。如果我禁用此弹出窗口(“showActionsheet”),一切都很好。

就像我回到tableView一样,在“DetailView”中调用的弹出窗口不再存在。

请求帮助。

1 个答案:

答案 0 :(得分:0)

首先,您是否在objc_exception_throw和[NSException raise]异常上添加了断点?

此外,因为ActionSheet已添加到子视图中,然后直接添加到子视图中:

[self.navigationController popToRootViewControllerAnimated:YES];

动作表不是模态对话框或其他任何内容,它不会阻止同时调用其他函数。

如果您执行以下操作,可能会有所帮助:

-(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];
}

这样,didDismissWithButtonIndex方法知道实际使用了哪个动作表以及下一个动作应该是什么。

当你仍在使用视频时,你永远不应该移除视图,就像你一样。