Instantiating Modal view controller freezes the ap

2019-02-18 06:45发布

问题:

I am presenting a view controller modally in iOS app. The issue is that there is no crash and the app freezes as soon as presentViewController:animated is called. The stats show the CPU usage to be 100% and the usage doesn't go down even after manually closing the app.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
CustomModalViewController *vvc = [sb instantiateViewControllerWithIdentifier:@"CustomModalViewController"];
if(!vvc){
    NSLog(@"ERROR!!! vvc is null");
}
NSLog(@"instantiate modal view controller");

vvc.providesPresentationContextTransitionStyle = YES;
vvc.definesPresentationContext = YES;
vvc.data = data;
NSLog(@"before presenting modal view controller");
[vvc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self presentViewController:vvc animated:YES completion:nil];

I tried printing some debug statements in the viewDidLoad of my custom class, but those are also not getting called.

I don't understand why the view controller is not being displayed. Any help will be appreciated. I want to know in what case does your app go into infinite loop on pushing a view controller or is it because of some other cause??

UPDATE:

This error occured after I updated to XCode 7. Not sure, but I guess this might be an issue with new SDK- the UIKit or LLVM compiler. I copied my project to another mac with Xcode 6.4 and the error disappears!!! I haven't changed any build settings either that would cause the issue.

Any pointers on how to proceed?

回答1:

Ok, this is bizarre, but I hope it helps: I have the EXACT same issue, the CPU jumps to 100% and view never shows. Works perfectly well in Xcode 6.4. In Xcode 7.1, on the view that I am calling, I have got a UITextView with some placeholder text "Notes:". What I found is that if I clear out the placeholder text, the view LOADS and all of the procedures execute as normal. If the placeholder text length is greater than 9 characters, the view also loads and procedures execute as normal. If the placeholder text length >0 and < 10, it's a no go. No view and CPU at 100%. This is odd, I realize, but hopefully it helps you out. Like you, I've got no errors or console output to show, it just spins.

EDIT FYI, blanking out the placeholder text in the storyboard, and just setting it in code fixes this as well irrespective of length



回答2:

Same issue here.

I have a UITextView with the default string " Text " and fails with 100% CPU load. I was putting the placeholder only in code but until I remove the " Text " from the storyboard didn't work.

My code was developed in Xcode 6 and I noticed this error after send a new app revision builded with xcode 7.