1

When I called:

[self.navigationController pushViewController:SOME_VIEW_CONTROLLER animated:YES];

the app randomly stuck (it didn't crash, so no error log). Have tried debugging it with no result.

Note that:

  1. I called this pushViewController from a UIViewController category. Is there any problem with that?
  2. I am not using storyboard
  3. The problem persist randomly (it doesn't happen all the time)
  4. When it stuck, viewDidAppear won't be called (viewWillAppear, viewWillLayoutSubviews, viewDidLayoutSubviews still called)
  5. the problem never occured when I use animated:NO

Some code snippets:

- (void)routeToBookingDetailsForCustomer:(BookingModel *)booking {
    VTBookingDetailsForCustomerViewController *vc = [VTBookingDetailsForCustomerViewController new];
    vc.booking = booking;
    [self.navigationController pushViewController:vc animated:YES];
}

Just found another thread with similar case: pushViewController stuck or viewdidappear fail

Cœur
  • 37,241
  • 25
  • 195
  • 267

4 Answers4

2

I think you have to pass Nib name as well like this

- (void)routeToBookingDetailsForCustomer:(BookingModel *)booking{
    VTBookingDetailsForCustomerViewController *vc = [[VTBookingDetailsForCustomerViewController alloc]initWithNibName:@"VTBookingDetailsForCustomerViewController" bundle:nil];
    vc.booking = booking;
    [self.navigationController pushViewController:vc animated:YES];
}

Nib name means your XIB name whatever XIB name for your VTBookingDetailsForCustomerViewController, you have to pass this in initWithNibName:@"yourXIBname"

Dipen Chudasama
  • 3,063
  • 21
  • 42
  • I don't get it, why should I initialized it with storyboard/nib? – Aruna Harsa Mar 18 '15 at 05:24
  • Without XIB where controller pushed ? – Dipen Chudasama Mar 18 '15 at 05:50
  • without XIB what will display in your screen..? this need to some view(XIB) do display your design.... – Dipen Chudasama Mar 18 '15 at 05:51
  • I changed my code to what you suggested, but it doesnt solve the problem. Moreover, as i mentioned, the problem is 'randomly occured'. If the problem is truly because there's no xib loaded, why would the view appear when the problem doesnt occur – Aruna Harsa Mar 18 '15 at 06:16
  • Must be some issue in your VTBookingDetailsForCustomerViewController . Show code of viewdidload, viewdidappear.Dont comment on both threads. I'll follow this thread. :) – Bista Mar 18 '15 at 06:21
0

Have you tried this approach?

someViewController *someVC = [someViewController alloc] initWithNibName:@"someViewController " bundle:NULL];
someVC.someVariable  = someValue;
[self.navigationController pushViewController:someVC animated:YES];

Edit : Just saw 'Dipen Chudasama' already answered!

Bista
  • 7,869
  • 3
  • 27
  • 55
  • I don't get it, why should I initialized it with storyboard/nib? – Aruna Harsa Mar 18 '15 at 05:23
  • Because, we have to tell the `pushViewController` that into which viewController it is going to. XIB(new name) and NIB(old name) names are same. So, we initialize class `someViewController ` and nib/xib 'someViewController' together. Because, we have to tell the `pushViewController` that into which viewController it is going to. XIB(new name) and NIB(old name) names are same. So, we initialize class `someViewController ` and nib/xib 'someViewController' together. [Refer](http://stackoverflow.com/questions/15633940/when-and-why-to-use-initwithnibnamebundle-in-development) – Bista Mar 18 '15 at 05:36
  • I changed my code to what you suggested, but it doesnt solve the problem. Moreover, as i mentioned, the problem is 'randomly occured'. If the problem is truly because there's no xib loaded, why would the view appear when the problem doesnt occur – Aruna Harsa Mar 18 '15 at 06:17
  • Must be some issue in your VTBookingDetailsForCustomerViewController . Show code of viewdidload, viewdidappear. – Bista Mar 18 '15 at 06:24
  • I don't think so, because I've removed all codes in viewdidload/viewdidappear. update: the problem is solved when I use animated:NO there's something wrong with the animation is it? – Aruna Harsa Mar 18 '15 at 06:31
  • [check this](http://stackoverflow.com/questions/21310611/ios7-navigationcontroller-pushviewcontroller-animated-bug) – Bista Mar 18 '15 at 06:39
0

Are you using custom transition animations by implementing UINavigationProtocolDelegate combined with UIViewControllerInteractiveTransitioning?

I struggled with this issue in my own application and it turned out that I was incorrectly starting an interactive transition which I never finished. In this case all debugging showed me that the controller was pushed but UI was not updated until my app changed states.

CÇ.
  • 243
  • 5
  • 13
0

Please try pushViewController code in main queue.

dispatch_async (dispatch_get_main_queue(), ^{

VTBookingDetailsForCustomerViewController *vc = [VTBookingDetailsForCustomerViewController new];
vc.booking = booking;
[self.navigationController pushViewController:vc animated:YES];

});
Milan Rathod
  • 326
  • 1
  • 2
  • 16