3

When I use pushViewController, viewWillDisappear (first view controller) is called. After that, the screen freezes, hence no action is performed and I put breakpoint on nextviewcontroller, it doesn't get called in viewDidLoad method.

//first View Controller from where pushViewController
 [[AppCommonFunctions sharedInstance]pushVCOfClass:[NextViewController class] fromNC:[self navigationController] animated:YES popFirstToVCOfClass:nil modifyVC: ^(id info) {
            [((NextViewController *)info)setEventInfo : object];
        }];


//common method for push view controller in another file
- (void)pushVCOfClass:(Class)class1 fromNC:(UINavigationController *)nc animated:(BOOL)animated popFirstToVCOfClass:(Class)class2 modifyVC:(operationACFFinishedBlock)modify {
RESIGN_KEYBOARD
[self popToViewControllerOfKind : class2 from : nc];
UIViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:[class1 description]];
if (modify) {
    modify(vc);
    modify = nil;
}
[nc pushViewController:vc animated:animated];
 }
        - (UIViewController *)popToViewControllerOfKind:(Class)aClass from:(UINavigationController *)navController {
RESIGN_KEYBOARD
if (aClass) {
    NSArray *arrayOfViewControllersInStack = navController.viewControllers;
    for (int i = 0; i < arrayOfViewControllersInStack.count; i++) {
        if ([[arrayOfViewControllersInStack objectAtIndex:i] isKindOfClass:aClass]) {
            int index = (i > 0) ? (i - 1) : i;
            [navController popToViewController:[arrayOfViewControllersInStack objectAtIndex:index] animated:NO];
            break;
        }
    }
    return [navController topViewController];
}
return nil;
}
Unheilig
  • 16,196
  • 193
  • 68
  • 98
Test At
  • 58
  • 2
  • 11

3 Answers3

3

I encounter this problem too. I found the CPU usage is 100% after pushViewController:animated:, and the runloop is stuck. The view controller fails to load the view in loadView.

The loadView process might be changed internally in iOS 9, or the storyboard/xib file is misconstructed due to Xcode 7 (maybe just a bug).

Step 1, try to load view before push

I've tried to print the view property to enforce the view controller calling loadView.

UIViewController *vc = ...;
NSLog(@"vc.view: %@", vc.view);  // Never print
[self.navigationController pushViewController:vc animated:YES];

I found the view can't be load when calling view property. The NSLog() will not print the view object, and the runloop is stuck.

Step 2, reveal the call stack when loading view

Adding the following loadView implementation in the target view controller.

- (void)loadView
{
  NSLog(@"will loadView");
  [super loadView];
  NSLog(@"did loadView");
}

Build and run your app, and try to trigger the loadView by calling the property view. Now you should find the app is stuck at [super loadView] in the target view controller.

Now try to pause the execution (Debug » Pause, or cmd + ctrl + Y) several times, and you should found that the app (runloop) is almost stuck at some specific methods. In my instance, my app is stuck at -[NSLocalizableString length] (or objc_msgSend).

I think this is a hint for debugging (My view controller is constructed by storyboard and the storyboard is localized in the project directly).


Update

After I reset the storyboard file back to previous version by version control (git), the app works well and the view is loaded successfully.

Xaree Lee
  • 3,188
  • 3
  • 34
  • 55
  • I had the exact same behavior and I had to recreate my entire viewcontroller in my storyboard and re-attach everything to my class – Brett DiDonato Sep 24 '15 at 14:21
  • following above step it stuck on objc_msgSend .... what i do to solve this problem? @BrettDiDonato – Test At Sep 28 '15 at 05:59
1

if your NextViewController have any UITextView you must have to give its default textValue in storyboard and changes its value from code by doing this it works fine for me you can also try.(i don't reason behind that but its working for me)

amit gupta
  • 1,167
  • 12
  • 29
1

This is a bug of iOS 9.0. UITextView should have minimum 10 characters by default. However you can change it later in viewDidLoad method. Reference : UITextView with text less than 10 characters hangs iOS 9

Community
  • 1
  • 1
Milan Gupta
  • 1,181
  • 8
  • 21