Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing UIcomponents with multiple threads
    primarykey
    data
    text
    <p>I'm really struggling with a multi-thread program that changes an IBOutlet when external variables change.</p> <p>With class header:</p> <pre class="lang-c prettyprint-override"><code>@interface QuestionViewController : UIViewController{ // IBOutlet IBOutlet UIBarButtonItem *changeButton; ... } </code></pre> <p>Starting the thread:</p> <pre class="lang-c prettyprint-override"><code> // Starts new thread with method 'statusPollMethod' to determine when status [NSThread detachNewThreadSelector:@selector(statusPollMethod:) toTarget:self withObject: @"Voting"]; </code></pre> <p>Begins:</p> <pre class="lang-c prettyprint-override"><code>-(void)statusPollMethod:requiredStatus{ GetSessionDataApi *statusPoll = [GetSessionDataApi new]; SessionCache *tempSessionCache = [SessionCache new]; ... @synchronized(self){ // Infinite Loop while(1) { // If sessionStatus is 'Voting' set button as displayed if ([[tempSessionCache sessionStatus] isEqualToString: (@"Voting")]){ NSLog(@"Status is Voting!"); // Ungreys and sets the button [changeButton setTitle:@"Submit"]; changeButton.enabled = YES; } // Wait for around 3 seconds [NSThread sleepForTimeInterval:3]; } } return; } </code></pre> <p>The problem is that the 2nd thread only occasionally completes any action on the IBOutlet. The IBOutlet is also accessed by the 1st thread, so I'm aware I probably have some multi-threading issues and I'm unsure how to protect the IBOutlet from this.</p> <p>As advised, I've looked through Apple Docs/Overflow posts, but I'm still confused.</p> <p>I really appreciate your help!</p> <p>Tim</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