現(xiàn)象
在A頁(yè)面的tableView的回調(diào)方法中使用present方法展示下一級(jí)viewController:B,出現(xiàn)延遲,斷點(diǎn)后了解到,點(diǎn)擊后順序執(zhí)行了presentViewController方法,但是completion沒(méi)有緊跟著跳進(jìn),B也沒(méi)有被present出來(lái),而且在當(dāng)前頁(yè)面A的等待時(shí)間跟在點(diǎn)擊A中該Cell前停留在此A頁(yè)面的時(shí)間呈正相關(guān),即點(diǎn)擊前停留的越久,present出B頁(yè)面就需要等越長(zhǎng)的時(shí)間,如果進(jìn)入A后直接點(diǎn)擊Cell進(jìn)入B,大概需要等不到1s;稍等3s后,需要等待5s以上。
原因
原因未知,可能是因?yàn)閜resent方法不是在主線程中執(zhí)行的
解決方法
把相關(guān)方法放在主線程中執(zhí)行
原代碼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* identifier = [_menuArray objectAtIndex:indexPath.row];
if (identifierRecordManager == identifier) {
UIViewController *vc = [[HHRecordManagerViewController alloc] initWithModulatorInfo:_info];
UINavigationController *nv = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nv animated:YES completion:nil];
}
}
放在主線程調(diào)用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* identifier = [_menuArray objectAtIndex:indexPath.row];
if (identifierRecordManager == identifier) {
dispatch_async(dispatch_get_main_queue(), ^{
//present方式呈現(xiàn),會(huì)出現(xiàn)界面延遲彈出的問(wèn)題,放在主線程中可以解決這個(gè)問(wèn)題
UIViewController *vc = [[HHRecordManagerViewController alloc] initWithModulatorInfo:_info];
UINavigationController *nv = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nv animated:YES completion:nil];
});
}
}
缺點(diǎn)
根本原因未知,治標(biāo)不治本