Designing views/windows in Mac OSX first time - cocoa

I am about to tackle my first Mac OSX project after developing for iOS.
In my iOS applications, it is clear to me the whole NavigationViewController->MyViewController->MyViews paradigm.
A bit more background on the iOS app so it would be easier to understand me:
The application is some sort of graphic viewer. Once you login you have a list of drawings, and if you select one, it opens it up.
Now in the iOS app I have a custom UIViewController that have some menu UI and a UIScrollView that holds a UIView in which I draw the drawing.
The custom UIViewController is responsible for acting as the "application" where the UIView inside is merely a graphic context.
Now - back to Mac:
I was thinking that my main window would show the drawings and once one is selected,
I would add another window with an NSView that is the graphic context of the drawing,
and the window will be acting as the UIViewController in the iOS app.
Does that make sense?

You can have NSViewController or NSWindowController on the Mac, to put your controller logic in. If you're going for separate windows, subclassing NSWindowController would make sense.

Related

OSX Multiple toolbars in NSTabViewController

I have a structure which is represented in the picture below (sorry but apparently in OS Sierra Xcode does not support anymore zooming in the storyboard -.- )
Window > TabController > View Controllers
Basically what I wanted to do is to have multiple toolbars, each one for a different ViewControllers. If I were on iOS I could have set a UINavigationController as target of the TabViewController and then do whatever I wanted with the related navigation bar, but here in OSX I cannot link the TabViewController to a WindowController (which handles the toolbar), hence having a window controller per view controller.
Is there any simple workaround for that?
Or the only solution is to empty-refill the toolbar with the correct buttons every time a Tab is selected?

How to incorporate a UISearchController into new (iOS8) UISplitviewController

I try to build a simple app based on the UISplitViewController template from Xcode 6 for universal apps (with Storyboard and CoreData/NSFetchedResultsController). This app should also provide a search bar for the MasterViewController. Unfortunately, Xcode 6 provides no InterfaceBuilder element for the UISearchBar/UISearchController combo (only the depreciated UISearchBar/UISearchDisplayController).
In the iOS Developer library, Apple provides the "Table Search with UISearchController" example, but this is not based on the UISplitViewController and supports only iPhone.
My problem is, that I'm not able to show the detail view on the correct ViewController under all circumstances. I tried to transfer the approach from the Apple example project to the UISplitViewController template. In this, one is encouraged to show the search results in a separate UITableViewController subclass (ResultsTableViewController) and use this as the searchResultsController of the UISearchController. I was not able to create a scene in InterfaceBuilder for this setup so I had to add these manually in code.
The problems begin when I click on a table cell of the ResultsTableViewController. This vc is not part of the scene in InterfaceBuilde and I don't know how to add it to the SplitViewController setting correctly. The biggest problem is the weird behavoir of the iPhone 6 Plus and the UISplitViewController. In portrait mode it behaves like an iPhone and doesn't seem to have a SplitViewController and only uses a NavigationController to which I push my DetailViewController. In landscape mode it behaves like an iPad with SplitViewController were I have to get the second ViewController of the SplitViewController childControllers and push the DetailViewController on this one.
Now it happens, when I start in portrait mode and switch to landscape mode that the DetailViewController is all gone, showing gray space where the DetailVC should be. It seems, when going to portrait mode, the DetailViewController gets kicked from the SplitViewController (or the SplitViewController gets kicked at all in favor for the iPhones NavigationController setup). When switching back to landscape the SplitViewController is initialized again but without proper initialization of the DetailViewController.
Is there any template or suggestion on how to correctly implement search capabilities on a universal UISplitViewController?
Cheers
Björn

NSWindow vs ViewController - OS X - Cocoa

I have been making iOS apps for a while now and I decided that I wanted to start working on making some of them for the Mac too.
The question I have is this: is there any need for an NSWindow, now that developing for the Mac is so similar to iOS??
So I made a simple cocoa application using Xcode and its comes with a storyboard called "Main", just like on iOS.
In that storyboard file, there is a NSWindow which then links to a NSViewController.
Can I get rid of that NSWindow? As I tried setting the NSViewController as the "Initial Controller" and the app still works fine. So whats the point of the NSWindow?
Also, what class links to the NSWindow? I was trying to blur that background of the NSWindow, but I have no way of linking code to the NSWindow.
Sorry for my stupid questions, but I am completely new to development for OS X.
Thanks for your time, Dan.
Those are many questions in one question:
Can I get rid of NSwindow? No, you need a window to show you views.
What is the point of the NSWindow? NSWindow is needed as the window in which the views are displayed and your events are going up the responder chain.
What class is linked to NSWindow? Obviously the NSWindow class, but that is not what you want to know. I think you want to know the delegate that controls NSWindow. This is NSWindowController, although for the MainMenu.xib it is NSAppDelegate.
Hope this gives you the answers you need. An example for working with views in a window is given in this question.
Please, see for further details the windows programming guide, which states:
The NSWindow class defines objects that manage and coordinate the
windows an application displays on the screen. A single NSWindow
object corresponds to at most one onscreen window. The two principal
functions of an NSWindow object are to provide an area in which NSView
objects can be placed and to accept and distribute, to the appropriate
views, events the user instigates through actions with the mouse and
keyboard.
For the question: Can I get rid of NSwindow? I have further comments. In most cases, You need a NSWindow to show view on screen; but in special case you don't, for example, a popup view when you click a NSStatusItem.
So my answer is whenever you need to respond window event such as min/max, you need NSWindow as the view container.

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.

Cocoa Single View question

Is there a way to have a single full-screen picture load when the cocoa app is launched? What I mean by that is a full-screen picture, without the menus and stuff that cocoa automatically attaches to apps.( For example, I want to build an app that when the user clicks it - it brings up a picture of say, a zombie, completely full screen - kind of like the end of that maze game.)
While I'm not aware of any maze games that feature a zombie at the end (though I imagine it would be a great companion to Plants vs. Zombies), you can achieve your goal by using NSView's built-in full-screen method -enterFullScreenMode:withOptions: and exit with -exitFullScreenModeWithOptions:.
To enter full screen at launch, just use the NSApplicationDelegate method -applicationDidFinishLaunching:.
As for UI arrangement, I'd just open MainMenu.xib in Interface Builder and delete the window, then drag an NSView ("Custom View") or just a NSImageView into the IB document and open it up. Create an outlet to the view in your app delegate / app controller and connect it to the view.

Resources