Note that there are some explanatory texts on larger screens.

plurals
  1. POShow UIActivityIndicator during segue navigation, after UIBarButtonItem press
    primarykey
    data
    text
    <p>I have a UIBarButtonItem in the navigation bar which switches to another screen, using a segue. This other screen takes some time to initialize, and I wanted to put a UIActivityIndicator on the UIBarButtonItem to show the tap has been registered, and the iPad is busy executing the action. </p> <p>My approach was to add a UIActivityIndicator to the UIBarButtonItem after it was pressed, then call <code>performSegueWithIdentifier:</code>, and in the <code>viewDidLoad</code> method of the second view, put the initialization into a <code>dispatch_sync()</code> call. You can guess it does not work... why?</p> <p>The IBAction on the first screen:</p> <pre><code>- (void)tappedEdit: (UIBarButtonItem *)editButton { // put activity indicator somewhere UIActivityIndicatorView *indicator; indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; indicator.frame = CGRectMake (200, 5, 50, 50); [self addSubview: indicator]; [indicator startAnimating]; // follow segue [self performSegueWithIdentifier: SegueShowDesignMode sender: editButton]; } </code></pre> <p>The initialization on the second screen:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // put costly operations into another queue to free main queue for activity indicator dispatch_sync (dispatch_get_global_queue (0, 0), ^{ // do initialization here }); } </code></pre> <p>The effect of this is that the UIBarButtonItem stays tapped while the initialization is performed, then the UIActivityIndicator is visible for a quick moment, and lastly the segue animation is shown, displaying the second screen. </p> <p>Any idea? Thanks a lot!</p> <p>EDIT: Probably an addition to the problem is that the initialization does some UIKit stuff: When I tried to use a semaphore, the initialization dumps with a BAD ACCESS in some UITextView method. I guess this is because it runs on some 'get_global_queue' and not on the 'get_main_queue'.</p> <p>EDIT AGAIN: Well, no. Using 'get_main_queue' results in a dead-lock, as announced in the Apple docs. So the question boils down to </p> <p>"How can I do background UIView creation (lots of!) while still having a spinner running?"</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload