UIActionSheet taking long time to respond

this is perhaps due to this

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

make an other methods and do this in that method. like this

[self viewRemover];

and in viewRemover

-(void) viewRemover
{
    [self performSelector:@selector(RemoveView) withObject:self afterDelay:3.0];

}

so your code will be like this now

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 performSelectorInBackground:@selector(viewRemover) withObject:nil];

    }
}

User interface actions run in the main thread and only occur when your method ends. So, MyThirdView will not appear until the other instructions have finished. The only thing I can figure is delaying that is:

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

If you are doing any heavy calculation or net conection, for sure that is the reason.

OTOH, I think you'd better modify that line:

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

if you want to simulate a button touch action.


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

This could be due to 1 of 2 problems.

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

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

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