Richa Srivastava Richa Srivastava - 3 months ago 15
iOS Question

UILabel is not showing in neither in simulator or iPad

So i am showing a model controller on top of a view controller. And i have texts in the model controller, but somehow the texts are not visible. I tried everything but somehow labels are not visible. But of you stay on the page for like 30 -40 sec the text shows up. Also this model controller is called from main view controller after a successful service(REST) call. If i call the model without making the service call then labels are visible in simulator/iPad both. But if i call it after service call inside success block then labels are not visible. I tried adding the text programmatically but still same issue. I tried debugging using Color blended layers, but the label is not at all visible in the view somehow. :(

[self.serviceManager getCustDetails:account successBlock:^(NSDictionary * successDict) {
[self hideLoadingAnimation];
NSDictionary *custData = [[successDict objectForKey:@"txnData"] objectForKey:@"custData"];

self.showCurrYear = [iraContribData objectForKey:@"showCurrYear"];

if ([self.showCurrYear isEqual: @"true"]){
[self performSegueWithIdentifier:@"CSegue" sender:self];
}

} failureBlock:^(NSDictionary * failureDict) {
[self hideLoadingAnimation];
NSLog(@"Failiure Dict %@",failureDict);
}];


And this prepareForSegue method, -

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"CSegue"]) {
CustViewController *cVC = segue.destinationViewController;
cVC.delegate = self;
[cVC setModalPresentationStyle:UIModalPresentationFormSheet];
cVC.preferredContentSize = CGSizeMake(800,750);
}
}


Below is my screen in storyboard, but in simulator the label is not visible, only continue and close button is visible.

enter image description here

Please help!, any suggestions are most welcome. Thanks!

Answer

It is possible that the delay is due to a user interface update not made on the main thread.

Try to make sure that your code is executed on the main thread using dispatch_async like this :

[self.serviceManager getCustDetails:account successBlock:^(NSDictionary * successDict) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self hideLoadingAnimation];
        NSDictionary *custData = [[successDict objectForKey:@"txnData"] objectForKey:@"custData"];

        self.showCurrYear = [iraContribData objectForKey:@"showCurrYear"];

        if ([self.showCurrYear isEqualToString:@"true"]){
            [self performSegueWithIdentifier:@"CSegue" sender:self];
        }
    });
} failureBlock:^(NSDictionary * failureDict) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self hideLoadingAnimation];
        NSLog(@"Failiure Dict %@",failureDict);
    });
}];
Comments