我有一个连接到新 View Controller 的按钮。当我按下按钮时,在新的 View Controller 出现之前有一个可见的 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)prepareForSegueUIStoryboardSegue *)segue senderid)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
-(void) viewWillDisappearBOOL)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
Best Answer-推荐答案 strong>
想通了。原来滞后时间在这一行:
[super viewDidLoad]
从destinationViewController viewDidLoad 方法调用。那是重新加载每次启动 segue 的 View ,这是一种繁重的方法。我评论了那条线并解决了这个问题。不知道为什么我每次都想重新加载 super View ...
关于iOS segue 慢 - 即使没有对destinationViewController 进行任何处理,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/28419849/
|