I have a view controller contains a table view that displays list of items. Each item could contains list of items (or could be a leaf).
To drilldow the list items, I would like to create a show/push segue, kinda in recursively way, but I seem not able to draw the manual segue to the view controller itself?
Is it supported?
I was playing around with it just after leaving that first comment - I don't think you can have a manual segue to the same view controller!
The best thing to do would be to give that view controller a storyboard identifier (e.g Selection and then create an instance of that view controller with (in Swift):
let subCategoryVC = storyboard.instantiateViewControllerWithIdentifier("Selection") as! SelectionViewController
or in Objective-C:
SelectionViewController *subCategoryVC = (SelectionViewController *) [self.storyboard instantiateViewControllerWithIdentifier:#"Selection"];
(Docs for UIStoryboard.instantiateViewControllerWithIdentifier:)
You could put that in your table view section method along with a manual segue to the leaf view controller.
(The code above assumes the view controller with the table view is called SelectionViewController!)
As Rich mentioned, this is probably not doable as for today. There are two workaround/solutions I can think of:
Instaniate the vc programatically from storyboard and programatically
use navigationController to push it. (I think this is what Rich was
talking about.)
Embed the View Controller in another Navigation Controller and draw
the manual segue to the Navigation Controller.
I choose the 2nd one just because it is very easy and more visual in storyboard. The first one should just work, too.
Related
I'm fairly new to Mac development and am slightly confused by the new "storyboard" feature in Xcode 6. What I'm trying to do is segue from one view controller to another in the same window. As of right now, all the different NSViewControllerSegues present the view controller in a new window, be it a modal or just another window. What I'd like to do is just segue within the same window, much in the same way one would on iOS (though an animated transition is not crucial). How would this be achieved?
If you provide a custom segue (subclass of NSStoryboardSegue) you can get the result you are after. There are a few gotchas with this approach though:
the custom segue will use presentViewController:animator so you will need to provide an animator object
because the presented view is not backed by a separate Window object, you may need to provide it with a custom NSView just to catch out mouse events that you don't want to propagate to the underlying NSViewController's view
there's also a Swift-only glitch regarding the custom segue's identifier property you need to watch out for.
As there doesn't seem to be much documentation about this I have made a small demo project with custom segue examples in Swift and Objective-C.
I also have provided some more detail in answer to this question.
(Reviving this as it comes up as first relevant result on Google and I had the same problem but decided against a custom segue)
While custom segues work (at least, the code given in foundry's answer worked under Swift 3; it needs updating for Swift 4), the sheer amount of work involved in writing a custom animator suggests to me that their main use case is custom animations.
The simple solution to changing the content of a window is to create an NSWindowController for your window, and to set its contentViewController to the desired viewController. This is particularly useful if you are following the typical pattern of storyboards and instantiate a new ViewController instance every time you switch.
However.
The NSStoryboard documentation says, quite clearly in macOS, containment (rather than transition) is the more common notion for storyboards which led me to look again at the available tools.
You could use a container view for this task, which adds a NWViewController layer instead of the NSWindowController outlined above. The solution I've gone with is to use an NSTabViewController. In the attributes inspector, set the style to 'unspecified', then select the TabView and set its style to 'tabless'.
To change tabs programatically, you set the selectedTabViewItemIndexof your TabViewController.
This solution reuses the same instance of the ViewControllers for the tab content, so that any data entered in text fields is preserved when the user switches to the other 'tab'.
Simple way with no segues involved to replace the current view controller in the same window:
if let myViewController = self.storyboard?.instantiateController(withIdentifier: "MyViewController") as? MyViewController {
self.view.window?.contentViewController = myViewController
}
I create a new viewController on storyboard. I want that viewController's view to shown thru the window. So, as far as I understood, I have to transform that view to a NSVisualEffects view.
How do I do that using interface builder?
I already have a lot of objects on that view added using interface builder, so, it will be nice to solve that using interface builder.
thanks
1) You can delete the view in the outline view and then add a visual effects view as the view controller's view.
2) Add a effects view as the subview of the view.
3) Change the class type of the view controller's view in the inspector window.
Options one and two will let you see the effects view in Xcode. I would recommend using option 3.
I have a reasonably complicated UIView which contains several nested views which are displayed according to a variety of responses - all are laid out in a storyboard.
Is there a way to hide a view in the foreground to work on a view in the background? As its really fiddly selecting particular elements to arrange / style!?
I've been trying to figure out a nice way to do this, some function like hiding the view and its subviews from the storyboard (not from the actual application), but couldn't find anything.
This is not the nicest of ways but it is how I do it at the moment...
What I do is select the views I want to "hide" from the document outline and add a constant (screen width/height) value to its x/y origin value to push them out of the screen. I also change the document label for those views (Identity Inspector > Document > Label) to something like "Hidden" so I can later search for the "hidden" views from the document outline and put them back where they belong.
I have 2 work arounds.
A) Change the View Controllers size to freeform. Set its size to be really large so I can space out the views.
B) Use the sort order of the views Document Outline (lowest is front most) and add an image view (same as the view background) under the first view to block the others. Then delete it after finishing my edits.
or xcode developers could just simple add a design-visible checkbox for views and controls.... but ill take my rants somewhere else.
In xcode 7 you can do it from the storybord
for more details
https://stackoverflow.com/a/25213491/4879683
Maybe this could help you :
Open your storyboard in the Finder and edit it with a simple text editor (not xcode).
You will see it's just a xml file.Look for the view you want to hide, and add hidden="YES" in the parameters list.
That's what I do on my own project.
In Xcode when you select your storyboard, you have a panel that displays all your view controllers and their hierarchy. If you change the order of the elements you change the background/foreground order.
You can add extra views to the scene dock.
These views get initiated along with the view controller, but are not added to the view controller's view hierarchy. You can reference them using IBOutlets.
e.g. I have a full screen loading view that I added to the scene dock instead of covering up the view controller in the storyboard. I can add the loading view to the view controller's view hierarchy in code:
#IBOutlet weak var loadingView: UIView!
...
loadingView.frame = view.bounds
loadingView.autoresizingMask = UIViewAutoresizing.FlexibleWidth.union(UIViewAutoresizing.FlexibleHeight)
view.addSubview(loadingView)
Reference: https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/AddViewsToDock.html
Is it possible to change the frame of UITableViewController's UITableView frame inside Interface Builder? I want to make my table, which I instantiate in IB, a little bit narrower.
When you have create your tableViewController in IB, if you then go to the section on the right of the screen where all the options are set size to "freeform" then drag it to whatever you like. When you init it it will then get this frame. Unless it is within a container controller.
The best way to do what you are after is to create a viewController and add a table view to its view. Make the table view narrower that the main controller view and wire it up to an IBOutlet on your controller. If you then make your controller implement the and methods you will be able to use your table view exactly as you want to.
Hope this is of help to you, if this is unclear or you would like any extra help, let me know :)
You can change it in IB but unless you customize your view controller somehow, it will set it be full screen (module enclosing controllers like nav, tab bar, split view, etc.) That's just the way view controllers work.
From the Apple docs:
When a view controller is displayed on screen, its root view is
typically resized to fit the available space, which can vary depending
on the window’s current orientation and the presence of other
interface elements such as the status bar.
You can create another UIView to hold your table view and then have more control over the table view sizing, But then you won't be a table view controller and will have to implement some of the things that table view controller provides you, e.g., deselectRowAtIndexPath on viewDidAppear.
I'm just learning and playing with the apple Seismic XML example
http://developer.apple.com/library/ios/#samplecode/SeismicXML/Introduction/Intro.html
I've got most of it figured out, but the one area I can't get past is, if I want to remove the tableview controller and create a view controller populated with a tableview. I can get the tableview to appear fine, but no matter what I try I can never get it to populate.
In the viewdidload area I can setup the tableview, color the background, do whatever I want to do, but I seem to 'lose' control of it somehow.
In short, would someone please be able to give me the steps involved in correctly changing the tableviewcontroller to a viewcontroller with a tableview in the apple example?
Thank you.
Lian, you need to read the documentation on UITableViewController. http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html
I'm not sure what you mean by "remove the tableview controller and create a view controller populated with a tableview" or why you would want this configuration. If you're having trouble with populating the tableViewController, you just pass in the data, usually from an NSArray or NSDictionary in the cellForRowAtIndexPath method. You either need to select the UITableViewController template when you create the class file or include the UITableViewDataSource and UITableViewDelegate if you're adding a tableView to a ViewController.
If you mean you want to change the view controller on screen, then you're looking to pop to another view using the navigation controller.