2

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

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

然后,当我单击 破坏性ButtonTitle:@"Confirm" 时,“确认删除”弹出窗口消失并调用:

- (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”中调用的弹出窗口不再存在。

感谢您的帮助。

4

1 回答 1

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 方法就知道实际使用了哪个操作表以及下一个操作应该是什么。

当您仍在处理视图时,您永远不应该删除它,就像您现在一样。

于 2010-10-02T06:09:18.927 回答