我有一个按钮segue'到一个新的viewController。当我按下按钮时,在出现新的视图控制器之前会有3-4秒的可见延迟。我已经阅读了关于stackoverflow的其他问题,通常问题出在destinationViewController或sourceViewController(尚未完成)上。就我而言,如果我在destinationViewController的viewDidLoad上设置了一个断点,则即使执行该代码之前也会发生延迟。
另外,我的代码不会执行任何耗时超过一毫秒的操作。
这是我的destinationViewController的代码。我在prepareForSegue ...方法中什么都没有。
我如何摆脱这种延迟?谢谢!
如果您需要其他诊断方法,请随时提出,谢谢。
#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
最佳答案
弄清楚了。原来滞后时间在这一行:
[super viewDidLoad]
这是从destinationViewController viewDidLoad方法调用的。那就是重新加载每次启动segue的视图,这是一个繁重的方法。我对此进行了评论,并解决了该问题。不知道为什么我要每次都重新加载 super 视图...
关于ios - iOS segue运行缓慢-即使对destinationViewController没有任何处理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28419849/