UIActionSheet需要很长时间才能做出响应 [英] UIActionSheet taking long time to respond

查看:60
本文介绍了UIActionSheet需要很长时间才能做出响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在actionSheet:clickedButtonAtIndex委托方法上创建 UIActionSheet .

I am creating a UIActionSheet on actionSheet:clickedButtonAtIndex delegate method.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex     
 if(buttonIndex == 1){

        [self.myFirstView removeFromSuperview]; 

        if (!self.mySecondView) {
            [[NSBundle mainBundle] loadNibNamed:@"MySecondView" owner:self options:nil];
        }
        [self.mySecondView setFrame:CGRectMake(0, 0, 320, 480)];

        [[UIApplication sharedApplication].keyWindow addSubview: self.mySecondView];

        UIActionSheet * action = [[UIActionSheet alloc]initWithTitle:@""
                                                            delegate:self
                                                   cancelButtonTitle: nil
                                              destructiveButtonTitle: deleteContacts
                                                   otherButtonTitles: cancel, nil];
        action.tag = 102;
        [action showInView:self.view];
        [action release];

    }

我以与上述完全相同的方法处理此 UIActionSheet 的click事件.

I handle the click event of this UIActionSheet in the exact same method as above.

if(actionSheet.tag == 102){

    if(buttonIndex == 0){
        if([[NSBundle mainBundle] loadNibNamed:@"MyThirdView" owner:self options:nil]) { 
            [self.myThirdView setFrame:CGRectMake(0, 0, 320, 480)];
            [[UIApplication sharedApplication].keyWindow addSubview:self.myThirdView];
        }
        [self.mySecondView removeFromSuperview]; 

        [self.doneButton.target performSelector:self.doneButton.action withObject:self.doneButton.target];

        [self performSelector:@selector(RemoveView) withObject:self afterDelay:3.0];

    }
}

我面临的问题是 UIActionSheet 需要太多时间来响应.当我单击 UIActionSheet 按钮时,在 myThirdView 加载之前,它处于冻结状态2到3秒钟.我不明白,这种情况下的响应延迟是什么,因为我在 UIActionSheet 按钮单击事件方法中所做的第一件事是加载 myThirdView .其余代码仅在加载myThirdView的代码之后执行.但是,即使第一行代码似乎也要经过一段时间才能执行.有什么建议吗?

The problem I am facing is that, the UIActionSheet takes too much time to respond. When I click on the UIActionSheet button, its in a frozen state for 2 or 3 seconds, before myThirdView loads. I am not able to understand, whats the response delay in this case as the first thing I do in the UIActionSheet button click event method is to load myThirdView. The rest of the code is executed only after the code to load the myThirdView. But even the first line of code seems to execute after a delay. Any suggestions?

推荐答案

问题.UIActionSheet会冻结还是消失,并且在2-3秒内看不到第三视图?

Question. Does the UIActionSheet freeze, or does it disappear and the 3rd view isn't visible for 2-3 seconds?

这可能是由于2个问题中的1个引起的.

This could be due to 1 of 2 problems.

  1. 如果整个操作表都冻结了,那么当您启动该第三视图时,您正在做一些繁重的工作,您正在加载一些核心数据或大量资产,或者花费很长时间.如果是这种情况,则需要重新格式化如何加载该第三视图.我建议将任何繁重的工作推到后台(这意味着,如果您的xib中有很多图像,则可能需要将它们加载到代码中.)

  1. If the entire action sheet freezes, then you are doing some heavy lifting when you init that 3rd view, you are loading some core data, or a lot of assets, or something that is taking a long time. If this is the case, you'll need to reformat HOW you load that 3rd view. I'd suggest pushing any heavy loading to the background (this means if you have a lot of images in your xib, you may need to load them in code).

另一种可能性是,您要在第二视图下方添加第三视图,然后在3秒钟内不隐藏第二视图(通过延迟选择器来完成).如果是这种情况,只需消除延迟即可.

The other possibility, is you are adding the 3rd view BELOW the 2nd view, and then not hiding the 2nd view for 3 seconds (done by performing the selector with a delay). If this is the case, simply remove the delay.

我制作了两节课来帮助我安排执行时间并找到代码中的瓶颈,看来它们现在可能会为您提供帮助. http://forrst.com/posts/Code_Execution_Timer_for_iOS_Development-dSJ

I made a couple of classes to help me time executions and find the bottlenecks in my code, it seems like they might help you now. http://forrst.com/posts/Code_Execution_Timer_for_iOS_Development-dSJ

这篇关于UIActionSheet需要很长时间才能做出响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆