I'm creating an iPad version of an iPhone app (NOT universal). I created copies of all my .m .h and XIB files, and appended "iPad" to the end of each, as well as to all my classes. This of course was tedious and overly complex but I didn't know a better way.
My problem: When I connect the iPad File's Owner and First Responder to my iPad XIB (see image) Xcode connects the XIB shown below to the iPhone ViewController code and not the iPad ViewController code.
I then went to the code (see below) to see if I could instead connect straight from the code (with those little circles to the left of Outlet code lines) but to no avail. When I click and drag the line and let go over the XIB it doesn't work. It doesn't do anything.
How do I associate (for lack of a better word) my iPad XIB with my iPad code? The iPad XIB is already part of the target build, FWIW.
Click on FileOwner in iPad xib file..
Go to identity inspector..in the Utilities Section.
You will see the class name there..Make sure it points to the iPad code class
Make sure that you've included the correct File name in your XIB in the File Inspector. This should match the class you are trying to connect objects.
Check the class you given for each xib is correct .that is in the identity inspector
Try this
File->Reload All Class Files
File->Read Class Files (select MyClass.h)
Reconnect File's Owner by
a. Setting the Class to "MyClass"
b. Reconnecting the View to the File's Owner's View
Everything is back to normal now. Weird.
Hope this helps more than it confuses ;-)
Related
This is my first application with multiple views.
I have an app that uses a storybord (main app), and another app with a single viewController and a nib file.
I would like to merge the singleView app as part of the main app.
Is there a way to do it?
How do I add the nib, and attach it to its viewController?
*Also please state if it's something that is really not recommended to do or not.
Please let me know if any more info needed.
You could simply copy whole view controller from the xib of the "single nib" project to a storyboard project.
Select "View Controller" in the xib of the single nib project as shown in image below and press cmd+c.
Open storyboard and press cmd+v. Your view controller from xib should be copied as shown in image below.
Now you should copy ViewController.m and ViewController.h (or whatever they are called) files from the single nib project.
Open Finder, find those files and drag them to the storyboard project in Xcode (somewhere in the project navigator). Be sure to select items shown in following image when copy dialog is prompted.
Now you should reconnect outlets and actions to copied view controller .h (cmd + drag from storyboard to .h file - you should already be familiar with this process)
And now you build to see if everything is working.
You should be able to just copy your existing single view nibs content into your story board. Just open both projects and copy-paste.
HOWEVER: I usually opt against storyboards. Especially when you're working in a team, they really mess things up (because of their single file/monolithic nature). I'd rather suggest you work on different files for each screen and tie them together with code.
While this may not be a concern for you, it may well be one later on.
I'm working on an iPhone app again and I'd like to setup one view to be seen before another. I've added the view to my window and have specified the viewcontroller code that I'd like to use, but I can't find where on earth xcode specifies which viewcontroller in the window is displayed first. I'm sure it must be something obvious. I thought that the appdelegate seemed logical, but I don't see it displayed there. Any help? :(
Usually it is in the UIApplication setup code. Also try looking in your xib file as to the linkages setup there!!!
Without seeing more code or your setup, this is the best I can do!!!
As you can open the MainWindow.xib file you can see the part on the windows that specifies that from which viewcontroller it is gona load. (Like "Loaded From "RootViewController""). From the inspector of the window there is an option called NIB Name that gives you a list of view controllers available in your project.Changing these will change the setting of from which view controller you want to begin your app.
Hope this will help you.
I'm using xCode 4.2, and after creating the .h and .m classes separately, I go and add a .xib file of the same name. So now I have:
ExampleClass.h
ExampleClass.m
ExampleClass.xib
However, the ExampleClass.xib won't connect to ANYTHING. I try dragging it to file's owner, to anything, and it won't connect. How do I go about doing this? The differences I see are that when creating all of them at the same time (.h, .m, and .xib), I see that when clicking on file's owner, it has "searchDisplayController" and "view" in the Outlets under the Connections Inspector. The one I created after the fact, ExampleClass.xib, has no "Outlets" section. I may be overlooking something, but I've tried restarting xCode, looking at other example code, etc... and I can't figure this out.
The first connection is in the Identity Inspector, which you can quickly access by pressing Option+Command+3. You must also set the File's Owner's view Property to the main view in the nib. The second step is often overlooked, and that results in a seemingly inexplicable crash.
In Interface Builder, show the utilities, beyond that show the show the identity inspector and assign the custom class.
I have a navigation based iPhone app, and I want to load a view (MainMenu.xib) when the app is launched, instead of MainWindow.xib. If I change the target's "Main Interface", the app crashes when it is launched. How do I fix this?
You have to add the view you want to display on MainWindow.xib......in the IB of MainWindow.xib you have to change the name of the class as well as the nib name (give the name of the class)
After doing this make the object of the view in the Application delegate
In navigation based you also need to give the name of the class you want to display(this class is the class in which you had designed your table view)
adding this comment a few years after the problem first posted as can cause problems if you have Storyboards to manually change MAIN INTERFACE instead of choosing from drop down. If value in field is not a .storyboard file then xocde changes the plist setting to NIB based project and breaks the whole project.
See my comment here
What does "Main Interface" in Xcode actually *do*?
I'm reading through a beginners iPhone text book and just finished writing all the code for a route tracker app that uses Map Kit and Core Location. I have the app running with no errors on my iphone 4 device but when I tried interacting I realized that none of my IBOutlets were connected to anything. When I referenced the beginning of the tutorial in the text, all it says is to "connect the appropriate outlets".
Here's why this usually simple task has me confused. The tutorial says to create a Window Based Project, so there is no ViewController. Then, in Interface Builder, the view is built in MainWindow.xib. The only IBOutlets of the project are located in Controller.h / Controller.m files that you create and which contain mostly all of the code for the app.
I usually ctrl-drag from File's Owner to the UI in Interface Builder, but in this project there seems to be no way for me to access the IBOutlets in Controller.h / .m from the MainWindow.xib file.
I'm frustrated because it seems like this should be such an easy fix but I'm totally stumped.. any help is really appreciated. Thanks
As I see it, you have two choices:
Add the outlets to the app delegate. This is probably not the best plan.
Put an instance of your controller class in the .xib file.
I think option 2 is what you want. If you check the Controllers section of the library, you'll see a component called "Object". Drag one of those into your xib, then inspect it. Select the info pane in the inspector (the circle with a white i in it) and change the Class to the name of your controller class.