How to switch between view controllers on the iPad? - xcode

Usually I've used NSNavigationController to switch between different view controllers smoothly. Now, on the iPad, I need a way to switch between view controllers, but am at a loss, since it seems that I cannot start a UINavigationController iPad app from Xcode. The only substitute I've found is SplitViewController -- I don't wish to display my app in this manner. In short, all I need is:
NEED: A way to smoothly transition (Switch) between UIViewControllers (the views therof?) from my application delegate.

The templates are just starting points to make initial configuration easier. You can just as easily start with the View- or Window-based Application template and then reconfigure it however you like.
Though keep in mind that Apple has not made iPad an option on the Navigation-based Application template for a reason (transitioning the entire window in an iPad is discouraged in the user interface guidelines).

Related

XCode 7: Launch screens may not set custom classnames

I created a simple application using Xcode 7 Beta 2. The application simply contains class MyAppDelegate, MyViewController, MyMain.storyBoard and MyLaunchScreen.storyboard. After recompiling the application with Xcode 7 Beta 4 the error "Launch screens may not set custom classnames" appears. Any suggestions?
Note that the launch screen is not a fully customizable view controller. You cannot specify a custom class name in the storyboard and expect the system to give you the option to execute code at this stage by calling viewDidLoad. Remember, the app hasn’t launched yet.
Launch Screen Constraints
The system loads the launch screen file before launching the app which creates some constraints on what it can contain (some of which may force you back to static image files):
The app is not yet loaded so the view hierarchy does not exist and the system can not call any custom view controller setup code you may have in the app (e.g. viewDidLoad)
You can only use standard UIKit classes so you can use UIView or UIViewController but not a custom subclass. If you try to set a custom class you will get an Illegal Configuration error in Xcode.
The launch screen file can only use basic UIKit views such as UIImageView and UILabel. You cannot use a UIWebView.
If you are using a storyboard you can specify multiple view controllers but there are again some limitations. For example you can embed view controllers in a navigation or tab bar controller but more complex container classes such as UISplitViewController do not work (at least not yet).
Localizing the launch screen file does not currently seem to have any effect. The base localization is always used so you will probably want to avoid text on the launch screen.
You cannot specify different launch screen files for iPad and iPhone. This may be a problem if you have significantly different interfaces for those devices as there is only so much you can do with auto layout and size classes.
If you are deploying to iOS 7 you will still need to include the static launch image files. You can include both a launch screen file and static launch images. Devices such as the iPhone 6 running iOS 8 will use the launch screen file whilst iOS 7 devices will fallback to the launch images.
For more details please click here
This is a simple answer, but something I did and didn't even know it. I think with iOS 7, there is now a main.storyboard and a launchscreen.storyboard. I was unwittingly trying to build my initial functional screen on the launch screen.storyboard. That's a no no.
Hope this helps and happy coding!
Go through your View Controllers in Main.storyboard and make sure you don't have one that is both set to a custom class:
and has "Is Initial View Controller" checked:
You can only do one or the other. Somehow I had "Is Initial View Controller" still checked by mistake, and it took me a while to hunt that down!
I recently created an app using the Xcode 8 beta but couldn't submit it to the app store using the beta software. I had the same error message: "Launch screens may not set custom classnames" and several other.
My solution: Go to the File Inspector of the Main Storyboard and deselect the Use as Launch Screen option. Simple, right? Hopefully this works for you too.
Here's an image of what to look for

When I build my app my simulator looks different from my viewcontroller.xib

I was making a user interface using storyboards and when I built my app to see how it would look in the iOS simulator it didn't look like the viewcontroller in the storyboard (some of the buttons were moved around and I had to move one button way down so it was in the place i wanted it to be). Does anyone know why this is?
Yes, the reason is auto layout, it will automatically position elements on a relative basis depending on the device you're running.
You can turn autolayout off, or build for all devices at once and keep it on.
You may want to read iOS Auto Layout Demystified by Erica Sadun which goes in depth to the world of autolayout.

High-Level App Design/Architecture

I've done a fair amount of iOS development in the past couple of years, so I'm pretty familiar with iOS architecture and app design (everything's a ViewController that you either push, pop, or stick into tab bars). I've recently started exploring proper Mac app development and feel a little lost. I'd like to really just have a sanity check and maybe some advice as to what the proper way to build an app like this is:
I'd like to build a library-style, single window app, that will spawn additional windows during its operation, but not as full-blown documents. The main window will be laid out much like OS X Lion's Mail.app, with a three-wide split view containing:
A source list, or high-level topic selection
A list view of items pertaining to the topic selected in the first pane
A detail view, which shows the details of the object selected in the middle pane
Like I said, really similar to Mail.app as far as looks go.
My question is really how to glue all this together from inside XCode. Here's where my confusion lies so far:
The default project generated a NIB with a main menu and window. I like to encapsulate functionality, so should I make a window controller for this window and somehow hook it up in Interface Builder, or does window-specific functionality belong somewhere else?
If possible, I'd like each of my three panes to be separate view controllers. I created three NSViewController subclasses (XCode automatically generated NIBs), and added (to the main menu/window NIB) view controller objects with each class specified, hooking up each one's view property to one of the three Custom View generic NSView objects I dropped into the NSSplitView. When I tried to set each view controller's NIB, only the main menu/window NIB appeared in the drop-down, and typing the desired one by hand seemed to have no effect (the view's contents didn't actually appear when running the app). This makes me think I'm doing something wrong.
I'm a little fuzzy on what types of views I should use for each of the first two panes. I'll obviously build a custom one for the final pane, but it seems like the first two should be present in the Cocoa framework already.
Anyway, if I'm doing completely the wrong thing, don't bother addressing my questions; just tell me what I should be doing instead. I think I just need a proper Mac developer to point me in the right direction.
With regard to your first question, you don't need to use the main window that Apple supplies in MainMenu.xib. If you want, you are free to delete that window from the nib and then instantiate an NSWindowController in your applicationDidFinishLaunching: delegate method which then loads and controls the main window.
You are definitely confused about NSViewController, which is not really all that surprising, since you might assume that it works like UIViewController.
In fact, NSViewController is completely different to UIViewController and does not have the same level of Interface Builder support. You can't place a view controller in a window in IB, for example, whereas this is standard practice on iOS. NSViewController is a relatively new class on the Mac and generally you use it to load views programmatically and manage the view content.
The class that most closely maps to UIViewController on the Mac is NSWindowController. This has been around a lot longer than NSViewController and in fact many Mac apps don't use NSViewController at all.
Generally, each window in your app should have a window controller managing it. You can use subclasses of NSWindowController to handle a lot of the functionality for each window.
If you want to use NSViewController, then you should use your window controller to manage those view controller objects. This is generally done programmatically due to the aforesaid lack of Interface Builder support. Each NSViewController instance loads its view from a specific nib file. You generally don't add view controllers in Interface Builder.
For your source list you would generally use an NSOutlineView if you have multiple sections or an NSTableView. These two objects are used whenever you need a list of items. NSOutlineView is hierarchical, whereas NSTableView is flat.
I hope this helps.

iPad SplitView as subview

I'm dealing with an iPad project that manages a custom menu and a subview with different stuff on in it, now i want to try to put on this subview a splitview. Is it possible? How can I do it? How can I build my splitview without any template?
The Apple human interface guidelines forbid this and say that the UISplitViewController must be installed as the Root View Controller so it would be best to redesign your app with this in mind since they will not approve it when submitted for review otherwise.
Whilst this is an old question it's still worth adding that Apple seem to have relaxed their rules. I have had a couple of apps approved that have a SplitView inside a TabBar.

first mac app - push viewcontroller

I have a question, I do some iphone application and now I want to do a little mac application.
From a clean application I add a button on MainMenu xib, than I add a NSViewController to MainMenu (from IB) with one Action.
I create a new NSViewController (FirstViewController) with a nib file and a button.
Now I want only to create a function to push FirstController from MainMenu and a simple function to push MainMenu from FirstController.
something like this
ViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController: ViewController animated:YES];
How can I do it???
I think you're trying to bring an iOS-style interface to MacOS X, and that won't work in many cases. The MacOS X user interface is very different from that of iOS.
iOS apps are limited to a single (and often small) window, and users generally do one thing at a time. The navigation interface standardizes the way that users drill down through different parts of a task so that the journey is predictable. The interface is very modal in the sense that the user is constantly navigating between different parts of the app, and user actions are often linked to the part of the app that's active.
The desktop, on the other hand, has plenty of screen space and allows multiple windows. Desktop apps should be modeless -- a user doesn't navigate through the app, but sees the whole thing laid out before him or her. As much as possible, the user should be able to perform any action at any time.
For these reasons, there is no navigation controller in Cocoa similar to Cocoa Touch's UINavigationController. If you can tell us more about the tasks that your two view controllers manage, perhaps someone here will help you think of ways to translate that better to the expected desktop experience.
Here apple discusses the migrating iOS to OS X strategies. Your scenario is also discussed here:
For example, AppKit uses the NSBrowser class to manage the display of
hierarchical information; in contrast, an iOS app would use navigation
controllers.
And NSBrowser can be seen in use here with the output as shown in the attached image.

Resources