Question

In the app I am making the app gets the value from a webservice to check if someone is following somebody else. When the value is YES the slider has to be updated to ON. When I update the switch in the ViewDidLoad the switch gets updated. In the code after the webservice check the switch isnt being switched on. The 'YES, user is following' does show up in the log file.

   if ([data length] >0 && error == nil){
        NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"%@", html);

            if ([html isEqualToString:@"isfollowing"]) {
                NSLog(@"YES, user is following");
                SwitchOutlet.on = YES;

                    }
    }
Was it helpful?

Solution

If you do the webservice check on the background thread, then you need to update UI on the main thread. Replace this line:

SwitchOutlet.on = YES;

with a block:

dispatch_async(dispatch_get_main_queue(), ^{

    SwitchOutlet.on = YES;
});

and let us know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top