2015-02-09 65 views
2

我有一個按鈕繼續瀏覽新的viewController。當我按下按鈕時,在新視圖控制器出現之前有一個可見的3-4秒延遲。我已經閱讀了關於stackoverflow的其他問題,通常問題是在destinationViewController或sourceViewController(尚未完成)上的代碼。在我的情況下,如果我在destinationViewController的viewDidLoad上設置了一個斷點,則延遲發生在代碼執行之前。iOS segue緩慢 - 即使在destinationViewController上沒有任何處理

加我的代碼不會做任何應該花費超過一毫秒。

這是我的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 
+0

真的很難確定,但解決的好方法是創建一個全新的項目,用一個單一的賽格瑞 - 在點點滴滴添加您所使用的代碼,看看它開始拖延。這也可能與Interface Builder中的某些內容有關或與AutoLayout相關。 – brandonscript 2015-02-09 21:39:11

+0

當目標視圖中的約束是'複雜'時,我已經看到類似的行爲。複雜可能意味着很多事情。在我的情況下,它是在父視圖內的7個按鈕被限制爲全部相同的大小。在縱向模式下,它快速加載,在橫向模式下花費幾秒鐘加載。我會用樂器來看看所有的時間都在哪裏。如果它被自動佈局的深處的方法所消耗,那可能是你的問題。 – 2015-02-09 23:00:36

+0

目標視圖控制器只有一個標籤和一個日期選擇器:s。 AutoLayout非常簡單。 – 2015-02-10 19:12:12

回答

0

想通了。發現延遲時間在這一行:

[super viewDidLoad] 

這是從destinationViewController viewDidLoad方法中調用的。這是重新加載每次啓動segue的視圖,這是一個沉重的方法。我評論說,解決這個問題。不知道爲什麼我會想每次重裝超級視圖...

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]; 
    }); 
}