Areeb Bajwa
Areeb Bajwa

Reputation: 31

iOS segue slow - even without any processing on destinationViewController

I've got a button segue'ing to a new viewController. When I press the button, there's a visible 3-4 sec delay before the new view controller shows up. I've read other questions on stackoverflow and usually the problem is with code on the destinationViewController or the sourceViewController (that hasn't completed). In my case if I set a breakpoint on viewDidLoad on the destinationViewController, the delay happens even BEFORE that code ever gets executed.

Plus my code doesn't do anything that should take more than a millisecond.

Here is the code for my destinationViewController. I have nothing in the prepareForSegue... method fyi.

How do I get rid of this delay? Thanks!

If you need something else to diagnose this feel free to ask, thanks.

#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

Upvotes: 2

Views: 1249

Answers (2)

Dinsen
Dinsen

Reputation: 2289

Do you have any code in:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

I did have [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

I tried adding it in dispatch_get_main_query and now it's smooth again.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    });
}

Upvotes: 1

Areeb Bajwa
Areeb Bajwa

Reputation: 31

Figured it out. Turns out the lag time was in this line:

[super viewDidLoad] 

which was being called from the destinationViewController viewDidLoad method. That was reloading the view that initiated the segue each time, and that was a heavy method. I commented that line out and that fixed the issue. Not sure why I would want to reload the super view every time...

Upvotes: 1

Related Questions