为什么动作在加载完成后执行多次,为什么它对所有事件进行排队?

Why action is perform multiple time after loading is finish and why it queuing all the events?

当我们点击后退按钮或 table 的任何单元格时加载时,加载后多次调用该操作是 finish.Here 我开始时正在做的代码片段加载并停止加载。

+(void)showLoader_OnView{
      APP_DELEGATE.window.userInteractionEnabled = NO;
     [MBProgressHUD showHUDAddedTo:APP_DELEGATE.window animated:YES];
}

停止加载:-

+(void)hideLoader {
    APP_DELEGATE.window.userInteractionEnabled =YES;
    [MBProgressHUD hideAllHUDsForView:APP_DELEGATE.window animated:YES];
}

请帮助我。

更新

实际上我正在从服务器获取数据。每当用户转到下一个 window 时,我都会在 viewWillAppear 函数中调用一个函数,该函数将点击 api 以获取数据。

-(void)performAutoSync
{
    @try
    {
        if(self.shouldPerformAutoSync)//Necessary conditions to check the auto sync
        {
            [AppConstants showLoader_OnView];  //here i call the loader.
            self.shouldPerformAutoSync  = NO;
            if(!self.isSyncing)
            {
                if(!syncBl)
                {
                    syncBl = [[SyncBL alloc] init];
                    syncBl.delegate = self;
                }

                if(!syncDl)
                    syncDl = [[SyncDL alloc] init];

                //            [self saveModifiedDataForCurrentViewController];


                [self delayToAutoSync];


                NSMutableDictionary *dictMainData = [NSMutableDictionary new];
                [dictMainData setObject:[syncDl fetchCompleteDataAndPrepareDictionary:YES] forKey:@"data"];//@"MainData"];
                [syncBl performAutoSync:dictMainData];
            }
        }
    }
    @catch (NSException *exception) {
        BILog(@"%@",exception);
    }

}

不要阻塞主线程。

看到您从 performAutoSync 调用 [AppConstants showLoader_OnView],然后 showLoader_OnView 依次执行:

[MBProgressHUD showHUDAddedTo:APP_DELEGATE.window animated:YES]

我只能假设performAutoSync是在主线程中执行的。当然,这会阻止 UI,直到您的操作完成。


你应该重新设计,这样你就不需要所有的状态变量、全局变量、全局调用,并利用多线程。

此外,请删除它,因为它属于杂牌;

APP_DELEGATE.window.userInteractionEnabled = NO