presentModalViewControllerAnimated: gives white screen - cocoa-touch

Hey all. Something which has been bugging me quite a bit recently is this custom movie player I've put together. It's largely based on a working one, NGMoviePlayer.
The issue is this: I have the .xib in a UIKit-friendly resource bundle. When I call:
[MyMoviePlayerViewController initWithNibName:#"MyMoviePlayerViewController"
bundle:[NSBundle bundleWithPath:
[[NSBundle mainBundle] bundlePath]
stringByAppendingPathComponent:#"MyMoviePlayerViewController.bundle"]];
..on my custom class, and then access the view (thus calling loadView) it doesn't throw any errors, but nor does it actually load the outlets properly. I am presented with a white screen, and debugging shows that all visual elements are 0x0, but there was no error as would be expected.
EDIT: I've also now tried just loading the .xib outside of a resource bundle in my target app, and the same thing happens (white screen).
The particular ones I was looking for was either:
Could not load NIB <nibname>... if it wasn't found at all, or
...loaded the <nibname> NIB but the view outlet was not set if it was found but not connected properly
The xib is in the local app (I understand that static libs can't contain xibs). I've tried using this same resource bundle with the NGMoviePlayerDemo project provided by the author of NGMoviePlayer, and it does throw an error:
Could not load NIB in bundle:
'/Users/.../MyMoviePlayerViewController.bundle (not yet loaded)'
with name 'MyMoviePlayerViewController'
I have navigated to the path it displays for the bundle and there exists a MyMoviePlayerViewController.xib file at that location.
I've also tried using bundle:nil in case Xcode combined the resources of bundle directories with the main one for some reason. Both cases throw no error and display a white screen in my actual project. Both cases throw a Could not load NIB error in the NGMoviePlayerDemo project.
EDIT: I have tried the same .xib separate from a resource bundle in the NGMoviePlayerDemo app and it works fine.
All input is greatly appreciated.

Solution: Pay attention to Unknown class <classname> in Interface Builder file. messages.
I had the code for the movie player in a static lib, and the parent view controller for the movie player was being included in the project as an external header, but the subviews weren't included as headers, so they weren't being located properly. Because the only place they were being referenced in my target app was within the .xib file, there were no compile errors to do with those subclasses, but when it came time to load the .xib those classes could not be found, so none of their properties were set. And that just so happened to include all of the controls for the player, which probably then made the initialisation code silently fall over.
I merged all of the code and ivars from the subclasses into the parent movie player class, and it's working fine now :)

Related

subclass of UIViewController is unable to call loadView method

i have a subclass of UIViewController, and when it is called from another class the app just freezes - i used the Xcode debugger and figured that when I'm trying to access the class's view property the app freeze. another weird thing is that when i type in the debugger control panel: "po objectOfTheProblematicClass.view" the debugger stops responding.
the code I used was similar to this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
WTStickyViewController *stickyVC = [sb instantiateViewControllerWithIdentifier:#"WTStickyViewController"];
stickyVC.sticky = sticky;
// Setup view controller containment:
[self.parentViewController addChildViewController:stickyVC];
self.containerView = self.parentViewController.view;
[self.containerView addSubview:stickyVC.view];
WTStickyViewController is the subclass of UIViewController. the app freezes when it reaches
[self.containerView addSubview:stickyVC.view];
but it's because this is the first time that stickyVC.view is called.
if for example i would put somewhere in the code
UIView *viewForExample = stickyVC.view;
the app would freeze there.
the exact same app works fine when compiled on a device with iOS 8 but has this problem with iOS 9.
if anyone knows why is this happening and if there is a solution it will be great. thank you.
I was having a similar issue and it was absolutely maddening. The CPU went to around 100% in the resource monitor during debug as the app deadlocked. Printing to console or just generally accessing the view controller's view property caused this behavior. Ultimately, what 'fixed' it for me was removing it from the base localization file. I know that doesn't make sense, but I'll elaborate as best as I can.
I'm maintaining a legacy universal app that has 2 'main' storyboards called Main_iPhone and Main_iPad, which as you can probably guess are the loaded dynamically based on what device you're launching on. I noticed that only the iPhone nib view was deadlocking as described, and iPad was loading fine. The only thing I could tell as that the iPhone storyboard had localization enabled while the iPad storyboard had not. So here's the steps I took loosely to remove it from base localization (you may want to do this in a separate branch/sandbox to make sure this works before deleting project references):
Right click the problematic view and/or storyboard in question, show in finder. For me it was inside the Base.lproj folder as expected.
[Re]move the file to a different directory so Xcode can not find the link the project (file goes red in file browser). Press delete to remove the file from the project file's reference from the project itself.
Add the file back at the new location in your repository/project structure so Xcode picks it up as a new file. Ensure all of your references to the file are updated to the new location.
Verify your storyboard/xib file is not localized anymore, clean project, re-run and see if the issue is still there (see image).
You can also just update the file location using the update location button in the file properties view on the right side (see other image).
Don't know if this will fix it, but I thought I'd share what helped me in the chance that it helps others as well.
A bug report was sent to apple and hopefully it will be fixed soon - the problem is indeed with Xcode 7.
If you are encountering a similar problem, it can be solved by doing one of the following:
1) Use Xcode 6.4, at least until apple fixes this bug.
2) Rebuild the problematic view in the storyboard.
I will post the radar link once I got a chance to speak with my manager about it...

Error loading .xib - application crash

I am banging my head against a brick wall. I am trying to push a view onto a UINavigationController in the usual manner:
[[self navigationController]pushViewController:vc animated:YES];
When I do this the app crashes with the following error:
__CFStringEncodeByteStream + 17
Thread 1: EXC_BAD_ACCESS (code=2,address=xxxxx)
Now, I have replaced the ViewController in question with a template provided by XCode and I do not get the error so the issue must be with my UIViewController class. Furthermore, if I replace the nib name with that of the template UIViewController class it works .i.e.
MyViewController *myVc = [[MyViewController alloc]initWithNibName:#"XCodeViewController" bundle:nil];
This leads me to think that the issue is actually with the nib and not the class itself. I have checked through all the connections and there are no errors or warnings.
Hopefully somebody can help.
Thanks
I was dealing with a very frustrating bug similar to yours, and everything was in place.
The newly created xib was added to the Bundle resources, no nil pointers or released pointer, NSZombieEnabled was set. The File's Owner was set to the correct ViewController as well
After sitting down with my senior for 30 minutes, we finally realized what was wrong -
In the newly created Xib, even after you assign the File's Owner to the ViewController there is an additional step which you need to take.
You need to have the main View's referencing Outlet set to the File's owner as well. The easiest way to do this is to Drag the "+" sign on the referencing outlet(From the Connections inspector) to the "File's Owner" in the Document Outline. After this you just need to click on "view" which pops up and you should be good.
Hope that helps you or anyone else facing the same problem
Need more info to answer, I can give few possibilities.
Check if the class name is mapped properly in your identity inspector.
And check your connections too. If your view is mapped in xib., etc.
If your running the app in OS below 6.0 & built with features such as Auto layout, it leads to crash.
There are multiple possibilities.
Hope this gives an insight.
Check if your nib is added to the application bundle. You can do that by selection you project file->Build Phases->Copy Bundle Resources.
If it is not there, add it.
I had the same issue yesterday and this was the problem.
I hope it helps.

iOS6: UIViewController was unable to load nib named

When testing in the iOS6 simulator, I am getting the following error when clicking a disclosure indicator:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] was unable to load a nib named "LocationDetail"'
It runs perfectly fine in iOS5.
I do NOT have the LocationDetail nib anymore, nor need to use it. I have looked in my entire project for references to it, as well as in my MainWindow nib and all connections looking to see where it could be used, but I find none.
How would XCode still be wanting to load this, and why only the errors in iOS6?
The problem is not in Xcode, but in the iOS Simulator. If you've removed all references to the .xib in your project, and cleaned everything as you described, the problem is that the .xib file still exists in the app bundle in the Simulator. You should try deleting the app from the Simulator (or better yet, Reset All Content & Settings on the Simulator). This will fix it.
what i know is that initWithStyle:UITableViewStyleGrouped will call the initWithNibName:Bundle: method...
your class had the same name as your nib file, so when you called the initWithStyle:UITableViewStyleGrouped it tried to load that nib file.
when you renamed your class, it didn't find an nib with the same class name so no errors showed up as before.
I decided to just rename my class and .h and .m files and that fixed the issue.
Who knows why.

deploy to device results in frankenstein binary

I'm unsure if this is relevant to my question, but I'll start at the beginning: In my project I have a view controller which is instantiated dynamically by class name, like this:
NSString* className;
...className is set to a valid class name, e.g. "someViewController"
Class c = NSClassFromString( className );
UIViewController* vc = [[c alloc] init];
In the current build of the project, someViewController is simply a specialized UIViewController. However, in an old build of the project (which was previously deployed to my device), the view controller of type someViewController was a specialized UITableViewController.
I spent a bunch of time this morning trying to understand why when I ran the build on the device (deploy from XCode), it would crash with an odd call stack and a console message:
[someViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xeb62a0
With much experimentation I found that if I swapped out the someViewController with any other view controller I couldn't repro the problem. And if I renamed someViewController to someViewController2 I couldn't repro the problem. The problem was with the symbol name someViewController. Then it dawned on me that someViewController USED to be a UITableViewController and would have had the tableView:numberOfRowsInSection: implemented.
In any event; deleting the app off of the device and having XCode deploy a clean copy fixed the issue.
What I want to know is, why? How? I guess I've known in the back of my mind for a while that XCode does funky stuff when deploying - I've had issues before where old resources stick around in the deployed bundle after they've been removed from the project. But I wouldn't have expected there to be issues with Objective-C types.
Simply renaming a .h and .m file and then introducing a new .h and .m with the same name will cause problems. Not to xcode, but to you. Best is to copy files to a directory like /tmp, delete them from the project, later add them to the project as new with a different name.

How do I initialize a window in Objective-C?

For a Mac graphics application (not iPhone), I need something like a main method in Java, the first method that gets a program going. I've been looking at things like NSViewController and NSWindow object. I've looked around but can't find an answer to this seemingly easy question anywhere. (I am very new at this by the way)
Thanks
If you create a Cocoa project from one of the Xcode "Cocoa Application" templates, you'll get a main.m file that includes the usual startup code.
Try working through one of the tutorial projects that you'll find in the documentation.
If you are using the project templates, the startup code is in the ApplicationDelegate file. The main.m, for a Cocoa application, sets up the run loop, runs NSApplication (as you can see in the Info.plist file under the 'Principle class' key.
This then loads the nib file that is specified in the Info.plist file (under the 'Main nib file base name' key). The default is MainMenu.xib. Now have a look at this nib file.
This is already set up by the template to have a 'Files's Owner' of NSApplication (the class that loaded the nib) But There is also a blue block which represents the application delegate. This is already filled out with one delegate method one outlet.
The delegate method is applicationDidFinishLaunching: This method is called by the application. This is only one of the possible delegate methods that it can handle, but it is sent after the run loop is started but before the application receives any events. It is the common place to put your initialisation code. It is in here that you should start to set up your window, which you can get to using the pre-supplied window outlet.
This is just a quick summary. A handy referenece is on Cocoa With Love and Apple's Introduction to Application Architecture document.