关闭 UI 操作表 - 崩溃

发布于 2024-09-25 17:07:05 字数 2966 浏览 2 评论 0原文

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

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

然后当我单击破坏性按钮标题:@“确认”时,“确认”删除”弹出窗口关闭并调用:

- (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:@“需求已删除”];“)出现。

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

就像当我返回 tableView 时,在“DetailView”中调用的弹出窗口不再存在。

谢谢你的帮助。

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 :

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:

-(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 :

- (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.

If i click "OK" my app crashes. If i disable this pop up("showActionsheet") everything is fine.

It's like while i go back to the tableView , the popup which was called in "DetailView" doesn't exist anymore.

Thx for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天荒地未老 2024-10-02 17:07:05

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

另外,因为 ActionSheet 被添加到子视图中,然后您立即执行以下操作:

[self.navigationController popToRootViewControllerAnimated:YES];

actionsheet 不是模式对话框或任何东西,它不会同时阻止调用其他函数。

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

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

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

First of all, did you put breakpoints on the objc_exception_throw and [NSException raise] exceptions?

Also because the ActionSheet is added to the subview and directly after that you do this:

[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.

You should never be removing a view when you are still working on it, like you are.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文