简体   繁体   English

UIView.hidden不会立即生效

[英]UIView.hidden doesn't work immediately

I have a UIViewController with a UITableView and UIView (see blow). 我有一个带UITableView和UIView的UIViewController(见打击)。 When I call hiddenLoadingView at somewhere, the UIView is still showing, then dismiss after 10-20 seconds, why? 当我在某处调用hiddenLoadingView时,UIView仍在显示,然后在10-20秒后解散,为什么?

- (void)viewDidLoad {
    ....
    self.tableView = [[[UITableView alloc] init] autorelease];
    [self.view addSubview:self.tableView];

    self.loadingView = [[[UIView alloc] init] autorelease];
    [self.view addSubview:self.loadingView];
}

- (void)hiddenLoadingView {
    NSLog(@"%@", [NSNumber numberWithBool:self.loadingView.hidden]);
    [self.loadingView setHidden:YES];
    NSLog(@"%@", [NSNumber numberWithBool:self.loadingView.hidden]);
}

Be sure to call hiddenLoadingView from the main thread. 一定要从主线程中调用hiddenLoadingView。 Sounds like you might be calling it from the completion block of some asynchronous method. 听起来你可能会从某个异步方法的完成块中调用它。

you have to call UI changes From main thread. 你必须从主线程调用UI更改。

dispatch_async(dispatch_get_main_queue(), ^{
// do UI related work here
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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