How to switch to a different scene without using .hidden to hide UI elements - xcode

I have just recently began learning Swift and Xcode and I have just started programming my first app. At the moment I am using .hidden to hide and show UI elements when the user taps on different functions to switch between different scenes. This seems very messy and unnecessary so I've been trying to figure out a better way to do it. I was experimenting with different things and discovered segues but I am not sure how I would switch to a new scene within a tab without losing the tab bar at the bottom?
Any help would be greatly appreciated.

I thought I would answer my own question now that I have been programming in Swift for a few months now and the answer is obvious...
Rather than hiding and unhiding individual objects, just drag a UIView into the view controller and you can add objects to that. You then simply need to hide the view, to which all of the objects are attached.

Related

Build a Cocoa UI for OSX

I'm trying to build a UI which look like this:
I'm using a storyboard with Xcode but I don't know how to start. I think a need different view in the window to manage button, text and tree but I don't know I to do it. I have try to use a split view but it gave me only 2 views instead of 3.
Any help in Cocoa and storyboard is welcome.
Thanks
Can't see where you'd want to use an NSSplitView but the UI you're attemting to create is trivial -
A plain NSWindow with the toolbar items configured as per your screenshot.
An NSOutlineView for the tree view with the three columns,
the content border of the window sized accordingly to make room for the label you intend to put at the bottom of the window.
As mentioned in the comments one way to populate the outline view would be to use an NSTreeController and Cocoa bindings. That's probably the only slightly more complicated bit about this UI..

Accordion-like folders on Cocoa for OSX?

I'm an intermediate iOS developer who's trying to jump on the OSX side of things.
I've been struggling to create an accordion-like display of several views, where only one view at a time can be unfolded to occupy the whole parent's view's available space. In other words, click on a view's title bar, it will both open/unfold this view and close/fold the currently open view, with animations'n'all. Oh end, I need the views' contents to be scrollable.
I tried starting from Apple's NSStackView sample code, but first it is not quite what I want, and what's more, I can't figure out how to start from here to end up where I eventually want to be.
Then I tried to master the Auto-Layout facilities but with no success. Truth be told, this whole Auto-Layout thing still confuses me some.
Does any of you have clues as to how I should proceed? Sample code? Tutorials (I tried several Auto-Layout tutorial but at the end of the day they still leave me missing the tricks I'd need to figure...).
Thanks.
/Julian
Check out the sample code: InfoBarStackView. It creates an accordion-like interface, the one difference from what you're describing is it lets multiple views be revealed at the same time (although, that's a simple difference).
It uses NSStackView and autolayout constraints to create the interface and drive the reveal/hide animations.
The stack view could also be put into an NSScrollView to allow the content to be scrollable. (Something similar was done during a WWDC 2013 Cocoa Animation talk).

Cocoa OSX custom widgets/controls

I want to know how can I create custom widgets/controls in Cocoa.
Not a full tutorial, but some guidance on what to start looking into. I'm confused by custom views, Core Animation, etc. I feel lost.
I see a lot of cool looking controls, like in Reeder App, or Sparrow etc. For example:
The left side is a collapsable menu that includes animations etc. How can I achieve something similar? I thought of using a WebView + HTML + JavaScript, but that doesn't seem like a very optimized solution.
Controls are views, so if custom views confuse you, you'll need to get that figured out before moving on to custom controls. Although you should really read the entire View Programming Guide, the section called Creating a Custom View will get you started on creating your own views. Try creating a simple view that draws a circle, for example, or the time.
When you've got views figured out, move on to custom controls. Most controls work about the same way. The user touches them, and the control responds by: a) tracking the user's input, b) changing its value, c) sending its action message to its target, and d) giving the user some feedback by redrawing itself. To get started, first make sure that you know how to use controls. Reading Control and Cell Programming Topics should help, and the section titled Subclassing NSControl covers (obviously) creating your own subclasses.
The example you provided is pretty clearly Apple's Mail.app. The view on the left side of the window might be an instance of NSOutlineView, or it might be a custom class. Either way, NSOutlineView would be a good starting point if you want to duplicate that functionality. NSOutlineView is a subclass of NSTableView, which in turn is a subclass of NSControl, which in turn is a subclass of NSView. Read Outline View Programming Topics for help getting started -- tables and outlines are extremely useful, but also more complicated to use than basic controls like buttons and text fields.
I know it's only a part of the UI, but I've recently coded something similar to the sidebar. If you look though the source-code it may give you some help on learning how to use custom controls and cells.
You can check it out on Github:
https://github.com/iluuu1994/ITSidebar

NSTableView redraw not updating display, selection sticking

Although I know of a solution to this problem, I am interested if someone can explain this solution to me. I also wanted to get this out there because I could not find any mention of this problem online, and it took me several hours over several days to track down. I have an NSTableView behaving strangely regarding redraws and its selection. The problem looks like this:
Table contents fades in, instead of appearing instantly upon it's appearance on screen. When scrolling through the contents, the newly appearing rows also fade in. When you make a selection (single or multiple), and scroll it off screen, then make another selection (that should replace, not add-to first selection), the first selection does not get cleared properly. If you scroll back to it, it is still there, in addition to your new selection. This is a display-update problem, not selection problem - i.e. your new selection is valid, it is just displayed wrong.
I tracked this through the NSArrayController I was binding to, the underlying Array, sorting, all the connections, and settings, etc., but all that has nothing to do with it.
What solved the problem was:
In the View Effects (right-most) Inspector, uncheck "Core Animation Layer" for the Window's main view.
Can anyone explain what is happening here, and perhaps improve upon the solution ?
It looks like Core Animation and NSTableView aren't getting along so well. The "fading" effect is a by-product of the way core animation works. When you have core animation in one view, it is also enabled in all of that view's subviews.
I don't recommend using core animation on the Mac unless absolutely necessary, because some interface elements (NSTextView and NSTableView, for example) aren't compatible with it. iOS has much better support for table views and such using core animation, mainly because it was designed with core animation in mind.
I know that some more simple UI elements are compatible (NSTextField and NSButton, for example).
If you absolutely need core animation in the rest of the window, put all the other views in a subview of the content view, while leaving the table view directly in the content view. You can then enable Core Animation in the other view.
Commenters, feel free to add to the list of what is and isn't compatible.

UIDesign Advice

I want to achiece the following scenario,
My idea is to have three different tableview. But i have stuck up with the scrolling problem that if i scroll tableview3 vertically, tableview1 & tableview2 should also scroll.
Is there any other idea for implementing this? Or else a solution for my scrolling problem?
Note: The number of columns are dynamic.
Happy Coding
I'm currently in the process of implementing a similar UI system, I gave up on using UITableView for it in order to make things a little more 'dynamic'. Re-implemnting all of UITableView from scratch is a really fun exercise!
If UITableView will still work for you, all you need to remember is tableview's are subclasses of UIScrollView, which has delegate methods for scrolling. Use those, along with setContentOffset and you can trivially sync the scrolling of multiple tables.

Resources