My project is in Xcode 4.2, designed for iOS 4.2 and above.
I am not using a Storyboard so in the Summary, both Main Storyboard and Main Interface are blank.
Will this cause problems with my submission to Apple?
I ask because when I set the Main interface to my primary View Controller, I get this error when I compile: this class is not key value coding-compliant for the key mainTableView.'
and I don't know how to resolve it.
From the ViewController Programming Guide:
"If a main storyboard is declared in this file, then when your app launches, iOS performs the following steps:
It instantiates a window for you.
It loads the main storyboard and instantiates its initial view controller.
It assigns the new view controller to the window’s rootViewController property and then makes the window visible on the screen."
The key word being "if". Therefore I don't think it's necessary.
I have a universal app that started out as an ios3 app and was updated to universal in the past 6 months - I didn't declare any storyboard (I've not used storyboards at all yet) or Main Interface. I simply add my viewcontroller's view to the window in applicationDidFinishLaunching.
When you state that you "set the Main interface to my primary View Controller" did you mean you set the view (not the view controller)? Is this a Xib file? A View Controller won't work, it needs to be a View/Xib.
Related
I would like to have my Swift Project load it's main Storyboard and View Controller from a Framework rather than the project itself.
Is this possible?
All help welcome.
I'm sure you have long since resolved your issue, but posting the answer here in case it's useful to someone else coming across it from Google.
You can specify another storyboard as the main storyboard by selecting your project from the navigator, selecting the app target from the left panel and going into the 'Info' tab. There is a setting there for "Main storyboard base file name."
For your specific issue, that's probably not what you want though. Instead, open your app's Main.storyboard, highlight the view controller, open the Identity Inspector, and set the Class to the one from your framework. To get this to work for my project, I actually had to delete the existing Main.storyboard, create a new one, drop a View Controller on it, and set "Is Initial View Controller" from the Attributes Inspector first.
Updated answer :
Let's assume you have a framework called myLogin with a storyboard with id "frameworkStoryboard" and a view controller with id "login".
You would
import myLogin
to load your framework and then put in your code
let storyBoard = NSStoryboard(name: "frameworkStoryboard", bundle: nil) as NSStoryboard
let loginViewController = storyBoard.instantiateControllerWithIdentifier("login") as! NSViewController
view.window?.contentViewController = loginViewController
to load your storyboard and corresponding view.
Basically you could use variables for both names (storyboard and controller) instead of just writing it down.
The example is for osx, the only difference for iOS would be using UIViewController instead of NSViewController, same goes for the storyboard, also you would not present the controller the same way on iOS (this example will switch the current windows content view instead of presenting it.
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 have an application, say 'MyApp', which by default loads the view controller 'MyAppViewController' whenever the application launches. Later, I added a new view controller 'NewViewControler' to the project.
I now want the 'NewViewController' to be my default view controller which loads when the app launches.
Please let me know what changes I need to make in my project to achieve this.
Its easy, just:
Open your Storyboard
Click on the View Controller corresponding to the view that you want to be the initial view
Open the Attributes Inspector
Select the "Is Initial View Controller" check box in the View Controller section
Open MainWindow.xib and replace MyAppViewController with NewViewController.
In your app delegate class, replace the property for MyAppViewController with one for NewViewController. Connect NewViewController to its new outlet in Interface Builder.
In application:didFinishLaunchingWithOptions: add NewViewController's view to the window instead of MyAppViewController's view.
Most likely your main NIB file is still set to "MainWindow", check your *-Info.plist file.
If that's the case you can open the MainWindow.xib in Interface Builder. You should see a View Controller item. Bring up the inspector window and change the Class Identity to point to your new class. That should take care of instantiating your class.
As this feels like a "newbie" question (please pardon me if I'm mistaken) I would also highly recommend the following article:
iPhone Programming Fundamentals: Understanding View Controllers
Helped me understand the whole ViewController thing and the IB interaction..
As for me with xcode 4.3.3, all I had to do was simply replace all references of 'MyAppViewController' with 'NewViewController' in the AppDelegate h and m files.
Perhaps all the other steps have been taken out in the newer versions of xcode.
Hope this helps.
This is a basic question about navigation controller, however, I don't seem to get it right.
I am creating a basic navigation controller application and using my custom view instead of the default rootviewcontroller and rootviewcontroller.xib that are automatically generated.
Here is what I have done:
Opened the MainView.xib and deleted the rootviewcontroller
Then, Xcode->new file->UIViewController class (with xib) and named it test
Opened mainview.xib, clicked on the section where it was pointing to rootviewcontroller and in inspector, changed the xib to test
In test, I just added a button.
However, when I load the application, the test doesn't seem to load. I added a log statement for viewdidload just to verify and the statement is never logged. Please let me know the fundamental connection I am missing here.
You must change the class of the RootViewController to your own (Inspector -> CMD+4).
I'm just starting iPhone development (coming fron a .Net world) and have been going through many "Hello World" applications to get the hang of this new development platform. One area I have been confused with is the instantiation of a view controller. On an Apple "Hello World" tutorial, they start by creating a Window Based App, which by default has no view controller. They then create a UIViewController and manually instantiate that controller in the application delegate, followed by simply adding the view controller to the window (http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhone101/Articles/03_AddingViewController.html#//apple_ref/doc/uid/TP40007514-CH5-SW5).
In contrast, if I were to create a new "View based application" project and look at the delegate implementation, all that was done to link that view controller to the main window was the following line:
[window addSubview:viewController.view];
Why does the tutorial indicate I must manually instantiate the view controller via alloc/init, when the pre-built "view based application" template simply adds the view controllers view to the window? What's the difference between the two?
From doing some more digging, I found out the answer to my own question. When you create a View Based Application, you'll notice that if you double-click the MainWindow.xib, one of the objects in the Document Window is a View Controller which is already connected to the [ProjectName]ViewController class (a class which was automatically created when you selected the View Based Application).
Hence, by dragging in a View Controller from the Library to the Document Window in MainWindow.xib, you are in essence INSTANTIATING that object (although it's archived in the nib file). Therefore, there is no need to instantiate it manually in the application delegate. Simply add that view controllers' view to the window and you're done.