Ios NSNotificationCenter可以';t将活动指示器设置为隐藏

Ios NSNotificationCenter可以';t将活动指示器设置为隐藏,ios,iphone,xcode,uiactivityindicatorview,Ios,Iphone,Xcode,Uiactivityindicatorview,您好,我在appdelegate中创建了一个nsnotificationcenter。下载完成后,它会发送一个通知。我的课堂上有一个活动指示器,当下载完成但不起作用时,我想隐藏它。我可以看到我的nslog,但它没有隐藏acitivyindicator 这是我的密码: viewdidload: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView:) name:@"loading

您好,我在appdelegate中创建了一个nsnotificationcenter。下载完成后,它会发送一个通知。我的课堂上有一个活动指示器,当下载完成但不起作用时,我想隐藏它。我可以看到我的nslog,但它没有隐藏acitivyindicator

这是我的密码:

viewdidload:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshView:) name:@"loadingFinished" object:nil];
我的职能:

-(void)refreshView:(NSNotification*)notification
{

    activity.hidden = YES;
    self.view.userInteractionEnabled =YES;
    NSLog(@"alles geladen zeiger wird geladen");



}

通知回调不能在主线程上调用,但所有UI更新必须在主线程中完成。因此,在通知回调中,使用
[self-performSelectorOnMainThread:@selector(refreshViewFromMainThread)]
,并声明一个新方法:

- (void)refreshViewFromMainThread
{
    activity.hidden = YES;
    self.view.userInteractionEnabled = YES;
}

通知回调不能在主线程上调用,但所有UI更新必须在主线程中完成。因此,在通知回调中,使用
[self-performSelectorOnMainThread:@selector(refreshViewFromMainThread)]
,并声明一个新方法:

- (void)refreshViewFromMainThread
{
    activity.hidden = YES;
    self.view.userInteractionEnabled = YES;
}

如果您在任何其他线程,那么它将无法工作cz UI无法在内部线程中工作。用这个

-(void)refreshView:(NSNotification*)notification
{


dispatch_async(dispatch_get_main_queue(), ^{
 activity.hidden = YES;
    self.view.userInteractionEnabled =YES;

        });    
    NSLog(@"alles geladen zeiger wird geladen");



}

如果您在任何其他线程,那么它将无法工作cz UI无法在内部线程中工作。用这个

-(void)refreshView:(NSNotification*)notification
{


dispatch_async(dispatch_get_main_queue(), ^{
 activity.hidden = YES;
    self.view.userInteractionEnabled =YES;

        });    
    NSLog(@"alles geladen zeiger wird geladen");



}