iPhone: View loading but not view controller - iphone

I had an issue with a project getting the dreaded "Error: cannot attach to process ID 0". Tried everything I could and it wanted nothing to do with me. So I started a new project and readded all my files and frameworks and what not in it.
Now my project runs. It shows me the first screen in my storyboard. However, the ViewController class attached to the window is not getting loaded and neither is the NavController class attached to my navigation controller. I reset the class in the Identity Inspector but still it wants nothing to do with me.
I added some NSLog(#"Test"); in the viewDidLoad methods of both my classes and they're not getting called. However, I added that same line to the AppDelegate applicationDidFinishLoadingWithOptions and that one did pop up in the debugger.
Any ideas?

I met that issue before, maybe it is some bugs of Xcode, the following steps works for me:
quit simulator
clean project
delete project's derived data
quit Xcode
restart Mac if you like
then reopen Xcode and everything is ok.

Related

How to fix "Thread 1: Exception: "Could not find a storyboard named 'Main' in bundle NSBundle" error in Xcode 11.4 when I do not have Main storyboard?

I know there are many questions here relating to this error but none of them. quite fit my situation. I have made an Xcode project trying to create a Star rating UIView with CocaoPods and Cosmos. I am following a tutorial. I was told in the beginning to delete the main storyboard and delete "main" as the main interface. So far I have installed two Cocao Pods on my project through the terminal and I am now using a new workspace that the Cacoa pods created. Every time I run the simulator, my app crashes and I get the error mentioned above but I can't do anything because I have deleted the main storyboard. I have tried making a new one and re-coding and more but nothing works. In the tutorial, the guy ran the exact same code that I have and he just magically has a storyboard with stars on it that you can tap and change. I've done everything he has, how do I fix this?
Here is my info.plist
To delete Main.storyboard as the main interface you have to delete it from the Info.plist file too. Look for the property "Main storyboard file base name".

How to correct "corrupt and unarchivable nib"?

I am writing a macOS app in Swift4. I'm targeting macOS 10.9, so I'm using xibs instead of storyboards.
When I try to run and open the nib via showing the window, it logs an error:
-[NSIBObjectData initWithCoder:]: corrupt and unarchivable nib file
-[MyWindowController loadWindow]: failed to load window nib file '/Users/toadzky/Library/Developer/Xcode/DerivedData/MyProject-cdudiyhqvfaauudsignqhtkqlfeu/Build/Products/Debug/My App.app/Contents/Resources/MyWindow.nib'.
The file is a xib, so i'm not sure if it's just an outdated error message. I'm subclassing NSWindowController and using the init(windowNibName:) constructor for my window controller.
I've tried restarting Xcode, cleaning and rebuilding the project, modifying the xib so xcode will rewrite it, etc. I haven't re-created it from scratch because it's a fairly complex view, and it's time consuming to redo so I'm hoping there's an alternative solution.
Update
I rebuilt the entire XIB from scratch, no copy-paste since I couldn't be sure what was wrong. Everything worked fine until I added some custom formatters using interface builder. Then it broke in the same way. I took them off and it worked again.
Two hours later, I added the custom formatters back and it works fine.
I'm leaving the question open in the hopes that someone will be able to provide some troubleshooting advice for when Xcode decides to arbitrarily not work for a while.
Make sure that in your init method you are initializing the super class and returning self.

iPhone app opens to black screen after refactor proj name in xCode 4

Guys, i wonder if any one can help - My project was fully working in both the simulator and on a device, however, i renamed the project in xcode 4 (double clicking at the root of the project navigation pane, it was happy to rename any references - but now when i launch the app it only opens to the main window (yes it has outlets, all have outlets etc etc),
no code in the app delegate stops at a break point (even in didFinishLaunchingWithOptions)
so unsure what i could have missed, i have looked at other answers and everyone writes and says "missing outlet" etc.
I have dragged some backed up version of the app delegate that used to work and no difference, what could i be missing.
I do have source control, however currently in the process of merging from VSS to GIT.
thanks
lee
Check your Info.plist for what it uses as it's Main Nib File. Perhaps something changed there? Also, within the nib file itself you might have problematic connections to classes that are still named with the old name.

Could not load nib in bundle on iPhone device

I'm trying to test an app I'm developing on my iPhone. To do that I changed the target from Simulator to Device on Xcode. The application is correctly uploaded to the device and it works. The main view is shown but if I try to open a secondary view, the application crashes.
On the iPhone log (I installed the iPhone configuration utility to see the console [is the only way to see the log from iPhone?]) I can see this error:
Could not load NIB in bundle
But, on the simulator it works fine. What's wrong? Any ideas?
I had the same problem and fixed it like so:
Open XCode Target
Click the "Build phases" tab
Click the "Copy bundle resources" section
Click the +
Add the missing Nib file
I've found that sometimes the device is case sensitive and the simulator is not.
What's the filename of your xib?
or
Try uninstalling the app from the simulator and installing it again - the simulator might have an old file left over from a previous run of the app - have you renamed / moved the xib at all during development?
I had a similar problem and was getting the same error. Turns out I was using the full name of the xib file in the attributes panel under "NIB Name:"
Don't use "SomeViewController.xib", just use "SomeViewController" without the ".xib" extension.
I had the same problem when invoking initWithNibName:#"MyViewController"
Changing the invocation to initWithNibName:NSStringFromClass([MyViewController class]) worked well
You can try these things:
Make sure case is correct
Use xib filename without the ".xib" extension
Remove any -(dash) or other special chars, use _(underscore)
Remove the xib file from the project and add back to the Xcode project
Check the build settings and make sure deployment is changed to currect SDK
In my case, the xib simply wasn't being copied into the bundle. Once I added the xib into the "Copy Bundle Resources" step for the application target, everything went fine.
I finally managed to solve that issue with these two steps:
In the view controller files inspector, remove any localization
(just for testing)
Ensure that you have checked the correct target membership
I don't know why it works on the simulator :(
For me, the problem was exactly what FreeAsInBeer said: the nib somehow was missing from the bundle, whereas it had been there before and worked properly in previous versions of the app.
To fix the problem, I did the following:
Select the project in the Project Navigator.
In the project settings select Build Phases.
Expand Copy Bundle Resources.
Scroll down (if necessary) and click on the + button.
In the dialog that appears, click on the Add Other... button.
Browse for the missing .XIB file in the file system.
Build and Run... the missing nib should appear when you run it.
This is just what worked for me when I got that message. Your mileage may vary, since circumstances are not always the same for everyone, but I hope this helps someone who runs into this issue.
-Evan
I ran into the same problem. In my case the nib name was "MyViewController.xib" and I renamed it to "MyView.xib". This got rid of the error.
I was also moving a project from XCode 3 to 4.2. Changing the Path type did not matter.
I had the same error message.
My problem, however was that my language settings on my phone were set on "English" and the Region on "United Kingdom". However, the file that could not be loaded was placed in the de.lproj directory.
Moving the file into the root directory solved it.
A simple mistake that might cause this error is trying to initWithNibName on an imported viewController when you are using a storyboard rather than individual Nib files. If this is the case then just init the controller instead of trying to init with a nib that doesn't exist, or init those fields with nil.
If Storyboard and no nib, change initWithNibName: bundle: to just be init OR initWithNibName:nil bundle:nil
For what its worth, I received this error when one of my tab bar buttons had the wrong class assigned to it.
I've got it to run with delete all of the localization from the xib
In the right window.
Maybe the file is in the localization folder.
I've the same problem. And my solution is remove all Localizations for the view.
I had exactly the behavior you described: works on simulator but get the "Could not load NIB in bundle" when running on the device, and the app remain stuck on the launch image.
In my case the problem was about the MainWindow.xib file that Xcode automatically created with English localization. I am supporting English and Italian in my app and realized that I was missing the localized version of MainWindow.xib for the Italian language.
Because I had no need to localize this file (it's Xcode default to create it localized) I fixed the problem by simply removing the English localization, so the same file is used independently of the localization. Another way to fix the problem would be to add the missing localized version, if you need it.
The app was crashing on the device because my device is configured for Italian language. The simulator instead was set to English and this is why the app run correctly. Just to verify, I set the simulator to Italian language and the app crashed confirming the localization problem.
I also had this problem when I loaded a child view controller from initWithCoder, which is a good place to initialise, but keep in mind you have to add it as an actual child AFTER the view has loaded.
So shift something like this:
[self addChildViewController: self.pageViewController];
[self.view addSubview: self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
...out of your init method and into viewDidLoad. Not saying this is your problem in particular but this may be helpful to others.

XIB File Not Loading Properly In Interface Builder

I was creating a new View-based Application in XCode, adding some outlet and actions, using the IBAction and IBOutlet tags, into the automatically created controller view header file. I then double clicked the 'project_name_ViewController.xib' to launch the interface builder.
However the outlets and actions did not appear in interface builder. The only way I could get them to appear was the close the xib file and reopen it through file -> open command in Interface Builder it's self.
I recently upgraded to Snow Leopard, before that I never had this problem.
Has anyone else come across this?
Xcode is full of strange bugs. I always follow my 15 step arcane black magic ritual before I make an ad-hoc or release build. Any time something like your problem happens, I put it down to the flying monkeys twisting bolts somewhere in Xcode and restart the program (sometimes the computer). That generally fixes it.
Of course with outlets and actions, it's easy to forget to save the source header before you swap over. Make sure to save and build. Errors in the source can stop them from showing up in IB too.