UIView没有直接显示

时间:2012-11-20 16:30:04

标签: iphone ios

这当然没什么,但是我遇到了一个并不能立刻出现的UIView。

以下是代码:

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;
}

它的工作原理是因为当我在loadLoadingIntoView中打印某些东西时,我看到了它,实际上问题是在完成fillParametersTables之后addSubview是有效的......

有谁知道怎么做?

谢谢!

1 个答案:

答案 0 :(得分:1)

您需要返回事件循环才能更新显示。一种方法是在将加载视图设置为自己的方法后放置行,然后使用performSelector:withObject:afterDelay:执行它。

E.g:

- (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]
}

(此代码是在HTML表单中编写的,甚至可能无法编译......但它应该对策略有所了解。)