【IOS】异步调用--- 简单使用记录
/××
×实现功能:店铺被删除后,先显示提示toast.然后,页面休眠5秒后,再返回到店铺列表页面。
×/
- (void)processDeleteShopError { _isLoadingData = NO; [_tableView refreshScrollViewDataSourceDidFinishedLoading:_tableView]; [self showToast:@"店铺被删除,返回店铺列表页面刷新数据"]; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ [NSThread sleepForTimeInterval:5]; dispatch_async(dispatch_get_main_queue(), ^{ [self backToPreController]; }); }); } - (void)backToPreController { [_shopEditDelegate shopDeleted:_shop]; [self.navigationController popToRootViewControllerAnimated:YES]; }
注意和以下代码比较,其效果不一样。
- (void)processDeleteShopError { _isLoadingData = NO; [_tableView refreshScrollViewDataSourceDidFinishedLoading:_tableView]; [self showToast:@"店铺被删除,返回店铺列表页面刷新数据"]; [[NSThread alloc]performSelector:@selector(backToPreController) withObject:nil afterDelay:2]; } - (void) backToPreController { [_shopEditDelegate shopDeleted:_shop]; [self.navigationController popToRootViewControllerAnimated:YES]; }
浙公网安备 33010602011771号