简体   繁体   中英

UIView doesn't directly show up

This is certainly nothing but I'm in trouble with a UIView that doesn't show up immediatly.

Here is the code :

SettingViewController.m

- (IBAction)reloadParametersDB:(id)sender {
    LoadingView* loadingView = [LoadingView loadLoadingIntoView:self.view];
    [dbService fillParametersTables];
    [loadingView removeLoading];
}

LoadingView.m

+(LoadingView *)loadLoadingIntoView:(UIView *)superView{
    LoadingView *loadingView = [[LoadingView alloc] initWithFrame:superView.bounds];
    if (loadingView == nil) return nil;
    loadingView.backgroundColor = [UIColor blackColor];
    [superView addSubview:loadingView];
    return loadingView;
}

It works because when I'm printing something in loadLoadingIntoView I'm seeing it, and actually the problem is that the addSubview is effective after fillParametersTables is done ...

Does anyone know how to do it ?

Thanks !

You need to return to the event loop in order to have your display update. One way would be to put the lines after you set up the loading view into their own method and then use performSelector:withObject:afterDelay: to execute it.

Eg:

- (void)doTableLoading:(id)loadingView {
    [dbService fillParametersTables];
    [(LoadingView *)loadingView removeLoading];
}

- (IBAction)reloadParametersDB:(id)sender {
    LoadingView* loadingView = [LoadingView loadLoadingIntoView:self.view];
    [self performSelector:@selector(doTableLoading:) withObject:loadingView afterDelay:0.1f]
}

(This code was written inside an HTML form and may not even compile...but it should give an idea of the strategy.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM