0

I use something similar to android toast to send messages to the user.

This toast is shown in the current view, in this case I want to change the view, and there is no time to read the message.

So, I use a thread to stay in the current view for 3 seconds, but the toast is also delayed.

[theHoleView makeToast:@"OK!!" duration:3 position:@"center" image:[UIImage imageNamed:@"nocorrect.png"]];
[NSThread sleepForTimeInterval:3];
[self.navigationController popToRootViewControllerAnimated:YES];

I execute NSThread after the Toast, why is the toast delayed?

Thank you in advance

user1256477
  • 10,763
  • 7
  • 38
  • 62

1 Answers1

1

It's because you haven't got back around the main loop which draws the screen. You can flush the graphics context with [CATransaction flush], ie

[theHoleView makeToast:@"OK!!" duration:3 position:@"center" image:[UIImage imageNamed:@"nocorrect.png"]];
[CATransaction flush];
[NSThread sleepForTimeInterval:3];
[self.navigationController popToRootViewControllerAnimated:YES];

You might need to add the Quartz framework for this to work, make sure the framework is added to the target and import the header in your ViewController.m file. ie:

#import <QuartzCore/QuartzCore.h>
Vic Smith
  • 3,477
  • 1
  • 18
  • 29