我有一个新的viewController按钮。当我按下按钮时,在新的视图控制器出现之前有一个可见的3-4秒延迟。我已经阅读了有关stackoverflow的其他问题,通常问题在于destinationViewController或sourceViewController上的代码(尚未完成)。在我的情况下,如果我在destinationViewController上的viewDidLoad上设置断点,则甚至在代码执行之前就会发生延迟。
另外,我的代码不会做任何超过一毫秒的事情。
这是我的destinationViewController的代码。我在prepareForSegue中没有任何内容......方法fyi。
如何摆脱这种延迟?谢谢!
如果你需要别的东西来诊断,请随意询问,谢谢。
#import "ViewSettingsViewController.h"
@interface ViewSettingsViewController ()
@end
@implementation ViewSettingsViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if ([HelperMethods getUserPreference:@"notificationTime"]==nil) {
NSDate * now = [[NSDate alloc] init];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents * comps = [cal components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now];
[comps setHour:19];
[comps setMinute:0];
[comps setSecond:0];
NSDate * date = [cal dateFromComponents:comps];
[self.timePicker setDate:date animated:TRUE];
} else {
[self.timePicker setDate:[HelperMethods getUserPreference:@"notificationTime"]];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// back button was pressed. We know this is true because self is no longer
// in the navigation stack.
[HelperMethods setUserPreference:self.timePicker.date forKey:@"notificationTime"];
}
[super viewWillDisappear:animated];
}
@end
答案 0 :(得分:1)
你有以下代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
我确实有[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
我尝试在dispatch_get_main_query中添加它,现在它再次顺利。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
});
}
答案 1 :(得分:0)
想出来。结果是这一行的滞后时间:
[super viewDidLoad]
是从destinationViewController viewDidLoad方法调用的。那是重新加载每次启动segue的视图,这是一个沉重的方法。我评论说排除了问题并解决了这个问题。不知道为什么我每次都想重新加载超级视图...