UIActionSheet taking long time to respond

Related searches

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

    }

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

    }
}

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?

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

UIActionSheet, In apps that target versions of iOS prior to iOS 8, use the UIActionSheet class to title and one or more buttons, each of which corresponds to an action to take. your application can still be terminated while in the background, so some type of actions that your app can perform in response to a local or push notification. 4. He texts you back at the same interval of time…always This might be a total coincidence. But if not, that’s just creepy. Did he read in a book somewhere that said texting back after exactly 67 minutes is the ideal waiting-time to get a girl to fall for you? 5. He texts back right away sometimes…and other time it takes him, like, 12 hours

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

    }
}

UIActionSheet Class (UIKit), A that displays an action sheet with one or more buttons. The following code and diagram are taken from the "Action Sheets" section of the Gets or sets whether the UIView will invert its colors in response to such an accessibility request. This is like how long it takes people to respond to a missed call from their parents, or finally start doing the homework they’ve been putting off for some time. That would mean you’re pretty important; the person just wants to have ample time to maintain the entire conversation once they finally do respond. 4-11 Hours:

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.

UIAlertController iOS. UIAlertView and UIActionSheet are…, UIAlertView and UIActionSheet are Deprecated in iOS 8 and Later. So Apple introduced a new controller for AlertView and ActionSheet called� I'm not telling you this to make you panic, but you need to know — there IS a time limit on how long you have to respond to a request for a date or to talk, etc. And that time limit isn't very long.

How big is your third view. if the nib file needs to load too much, you may be waiting for a lot to happen, also if you have to change some UI elements and your blocking the UI thread, you will hault your app until a timeout occurs and the app will shift some things to compensate..

the route I take with this is dispatch_async and dispatch_sync

// This will release the UI thread which may be blocking your calls.
// You can use any of the DISPATCH_QUEUE_PRIORITY_.... values to set how important this block is.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    // this command will get added to the stack and return without a hitch.
    // the block will be run the next time the main runloop ends.
    dispatch_async(dispatch_get_main_queue(), ^{
        // do some UI work that can happen without a hitch, and does not impact the calling block
    });

    // this command will act much the same. but will pause the background execution 
    // of this block until the runloop has executed this and returned.
    dispatch_sync(dispatch_get_main_queue(), ^{
        // do some UI work that must be completed to continue.
    });

});

doing too much in the UI thread will pause the execution of things that get stacked on the queue. Shipping all code to the background thread and only skipping to the UI thread when you need to alter the UI is a better and more responsive way to code your iphone app.

I hope this helps :)

UIAlertController, Did you know that UIAlertView and UIActionSheet (as well as their respective is called half the time, much less complain about its awkward parts. This week's article takes a look at UIAlertController , showing first by UIAlertView & UIActionSheet in favor of much more convenient completion handlers. Email Response Time. When it comes to personal emails, people appreciate a quick response time during normal working hours, but if you get back to them within 48 hours they're usually pretty cool about that. For business emails, people usually expect a response within a few hours, but a response within 24 hours is acceptable. Text Response Time

in Swift 4: I wrapped the code with this block

DispatchQueue.main.async {

// your code to show action sheet.

}

for example

DispatchQueue.main.async {

            let alert = UIAlertController(title: "Options", message: String("What do want to do?"), preferredStyle: UIAlertController.Style.actionSheet)

            alert.addAction(UIAlertAction(title: "Open", style: UIAlertAction.Style.default, handler: {(action:UIAlertAction!) in
                self.myOpen(code: self.codes[indexPath.row])
            }))
            alert.addAction(UIAlertAction(title: "Delete", style: UIAlertAction.Style.default, handler: {(action:UIAlertAction!) in
                self.myDelete(indexPath: indexPath)
            }))
            alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.default, handler: {(action:UIAlertAction!) in
                print("Cancel")
            }))

            self.present(alert, animated: true, completion: nil)

        }

EddyVerbruggen/cordova-plugin-actionsheet: ActionSheet , clipboard: ActionSheet plugin for Cordova iOS and Android apps Check the demo code to get you going quickly, or copy-paste some of the code below to� When I start new programs they either take a long time to start or they freeze. This happens sporadically, but enough to be a nusiance. I've followed all of the steps listed under the "fixit" section

Why Women Sometimes Take A Long Time To Reply To Texts - Duration: 4:18. Steven Mark Ryan 2,719 views. 4:18. She Takes Her Time To Respond - Duration: 5:48. Coach Corey Wayne 294,590 views. 5:48.

Some people are really calculating — and their response time depends on how they feel about the person. 7. "Usually as soon as I can compose a good response.If I just started talking to a girl

"The time it takes people to reply to respond to a request for a date; How we 'rate' someone can dictate how long it takes us to reply (Image: Getty) A person may have low self-esteem, or

Comments
  • does it work when you change [action showInView:self.view]; to [action showInView:self.mySecondView]; ?
  • It works. But no significant change in response speed of action sheet.
  • I think the right answer should be combining the answers of The Saad and Andrew Zimmer. The code that should be running on the background thread is this line of code [self.doneButton.target performSelector:self.doneButton.action withObject:self.doneButton];. The rest of the code including the RemoveView method should be running on the main thread. Special mention to Gabriel for simulating a button touch action.
  • First, I'm an anti-ARC coder myself, so I have some tips. Second, I'm kinda edgy about the way you wrote navigation, it looks messy but I can't give any suggestions with this minimal viewpoint. Tiptime: 1st, breakpoints to see what thread stuff is happening with. 2: performSelectorOnMainThread instead of performSelector. 3: Don't release the UIActionSheet until after callbacks are executed. 4: Ensure "self" still exists. 5: use breakpoints and step-thru to measure speed of handling functions
  • While debugging, the control doesn't enter the RemoveView method. Maybe it has something to do with withObject:nil in self performSelectorInBackground. Anyways the delay problem is still not sorted.
  • Oh and btw, if viewRemover is editing visible objects on the screen, DON'T do it in a background thread. This causes intermittent problems, not fun to debug.
  • No significant difference made.
  • This block of code has been a life saver for me. MAKE SURE TO NOT PASS AUTORELEASE OBJECTS TO IT. Since it's a block, sometimes you feel like you can.
  • I am currently using arc. But I believe the block retains and releases the objects it has a hold on all by itself. Does it not ??
  • I'm not sure if it does when you are using ARC, so you might be fine. Passing autoreleased objects between threads is rather disastrous if you aren't on ARC though. I've been burned by this in the past.
  • but a block is not quite a thread. the block freezes the current objects that are used across them. handling the retain and release itself. using dispatch you should be ok. as long as the block is created while the objects are still alive.
  • Hmm, looking elsewhere it seems that you are correct. I wonder what cause all those object released crashes.. Maybe because the object was outside of the scope of the method? Related: stackoverflow.com/questions/4983729/…