How to edit a View hidden behind other Views in Xcode Storyboard? - swift

Is there an easy way in Xcode to edit a view that is hidden behind other views within the Storyboard? I know I can hide the views in front of it and move the view to the front temporarily, but this is difficult to keep doing over and over again. Is there a way to isolate the view somehow in Storyboard so I can edit it on its own?

Select your view controller in storyboard and Open File Inspector
Select Use Auto Layout and Use Trait Variations
Now select the view you want to hide in your storyboard. Open Attributes inspector. Check/uncheck the installed option to show/hide the selected view. You can hide multiple views by changing this property after selecting all the views.
Don't forget to check this option for all the views while running the app. Else it will crash

Related

How do I get a crossfade transition with resize on macos using storyboard & NSTabViewController?

On a brand new MACOS application project (swift, storyboards), using the latest available version of xCode (8.3) I can't get a crossfade transition with a NSTabViewController that I add to my story board. The window is not resizing as well.
What am I doing wrong ?
I start by adding a new window controller, I remove its content view controller that I replace by a tabviewcontroller.
The tabview controller comes with two tabs wired to two view controllers. I resize one of them to make it bigger and put random buttons on both of them to be able to check wether the full view is visible or not at runtime.
Everything is left with default settings, as well as the "crossfade" transition of the tabviewcontroller.
But when running the application, tabs change abruptly, and the window doesn't resize to display the new tab.
My goal is to build a preference panel on my storyboard ans I just fail on the first steps.
For crossfade animation to work, you need to connect delegate outlet of the tab view to the tab view controller.
It does not seem smooth resize is supported by the standard tab view, though.

UITabBarController functionality with UITabBar

I'm making an app with interface builder using storyboarding.
I want to have a tab bar where no item is selected. This can be accomplished by setting
TabBar.SelectedItem = null;
But if you try to do that, you get the following error:
'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
So I can't use the standard UITabBarController. I've created a custom UIViewController, and added a UITabBar. Switching between tabs is working fine, and having no selection is also working as it should.
But I have no idea how to show my other view controllers from my custom view controller with the tab bar. Remember that I'm using interfacebuilder, so I can't just create my view controllers in code as new objects and add them to the view. (as suggested in UITabBar funcionality without UITabBarController)
So how do I show my own views without using the UITabBarViewController?
Edit: Still haven't found a solution, but I did a hacky fix. Simple create an other tab bar and place it on top of the original tab bar. Listen to those events and use SelectedIndex to change the view displayed. Then add some function that will select / deselect the items on your own tab bar.
In fact, even if you design your others UIViewControllers from IB, you can instantiate them from code. You'll probably have to play a bit with frame and autoresizing properties to make them fit the part of your main view you want them to display inside, but it's possible.
So, knowing that, a simple solution is to create a simple UIView (we'll call it 'tabFrame') in your main UIViewController, which fill the screen from the top of your UITabBar to the top of the screen; instantiate the UIViewController corresponding to your tabs and add their view as subview of tabFrame. Now you just have to catch item selection from tabbar to hide or show the desired subviews.
Hope I'm clear enough, else don't hesitate to question!
EDIT: pointed out this morning that in storyboarding context, you can effectively instantiate viewControllers / scene from code, but for not loosing designer settings it must NOT be done through directly calling their constructors, but through StoryBoard.InstantiateViewController("vc_identifier") calls, after having set identifiers to VCs in storyboard editor.
See http://docs.xamarin.com/ios/recipes/General/Storyboard/Storyboard_a_TableView for example

Where to write in viewcontroller using UITabBar

I have 4 different viewcontroller and these are connect with 4 tabs in UITabBar. I have to write respected code in each viewcontroller but I noticed the code which is written in each viewcontroller is not loading. Where to write code in each viewcontroller when it is loaded after selecting tabs in uitabbar?
You need to create a view controller file for each view (simply right click on the left where the files are and do New File -> UiViewController).
After that, in the Storyboard, select the view, and in the properties, change from the default view controller to the custom one you have created (this is the third icon on the right panel, under "Custom Class"). The UITabBar should handle switching the views, and your code will make the views run uniquely :)

Easy custom UITableView drawing

All,
I found the code in Matt Gallagher site ( http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html ) for this really neat design for a Table View... Im very new to Cocoa and Im having a hard time figuring out how to wire the darn thing in IB...
I loved the design and wanted to use something similar in a more complex structure... Nav Bar / Tab Bar with a few other views / TableView for the data in the first view... I found lots of tutorials to do that and got it working... When I tried to use that design in my project, things went crazy... in My MainWindow.xib I cant have a UIView where the arrow is pointing...
the nib looks like this:
Tab Bar Controller
Tab Bar
Nav Controller
Navigation Bar
Table View Controller
Table View
---->>>> (UIView for the backgroundImage )
Navigation Item
Tab Bar Item
UIView Controller
Tab Bar item
Window
can anyone guide me in the right direction??
Thanks !!!
It sounds like you're not having issues with the table view as much as the construction of the hierarchy around the table.
Instructions for creating the hierarchy would be as follows. I think you've diverged at around step 9:
Start with new copy of the default iPhone "View" template
Throw away the view controller class.
Open the MainWindow.xib and delete the view controller there too.
Find the controllers in the
Interface Builder library palette (they're
the yellow spheres at the top of the "Cocoa Touch" library in "Objects" mode whose icons contain
other objects).
Drag the tab view controller into
your MainWindow.xib file at the top
level.
Expand the tab view (triangle next to its name in the list view of the xib)
Drag a navigation controller into your expanded tab view (if this works, it should appear as one of the tabs along with the two view controllers that are there by default)
Expand the navigation controller
Drag a view controller (not a table view controller) into the navigation controller. It should appear as the content of the navigation controller.
Select the view controller (single click).
Press Command-4 (or select "Identity Inspector" from the "Tools" menu).
In the "Class Identity" popup menu, select EasyCustomTableController (this assumes that the current xib file is part of an Xcode project and this Xcode project already has EasyCustomTableController added to it).
Add a UIImageView to the view controller's view (this is your background image)
Add a UITableView to the view controller's view (this is your table). Add this view so it is after (and hence on top of) your image view.
There should be a tableView outlet on the view controller. Connect this to the table view.
Connect the app delegate's viewController to the tab bar controller (back in Xcode you can optionally change the type of this property to UITabViewController)
Should work.
The trick is that UITableViewController can't be used if you want the view to contain more than just a table. For this reason, you must use UIViewController and recreate the functionality that the UITableViewController adds. See here for how this is done:
http://cocoawithlove.com/2009/03/recreating-uitableviewcontroller-to.html
Thank you Matt (kind of cool that you answered)!!
I really appreciate the help... I've been messing around with it and got it to work using a UIViewController in another view (being created from the tableview)... Once I had the UITableViewController in the navigation I dropped the imageview & used a gray color; it looks great!! The initial screen has the rows big enough that scrolling is not an issue... I will go back and try to change that now...
I do have to say that IB is by far the most challenging step in app development for a newbie coming into Cocoa Touch !!! Yikes!

How do you set autosizing to flex in Interface Builder?

I have an iPhone project that I started as a Windows-based app and another View-based app. The Window app has a view which I added and I want to make the view fit within the window. In the View app the view is set to stretch.
Here is what it looks like when it is off.
(source: smallsharptools.com)
And here is when it is on.
http://www.smallsharptools.com/downloads/Stackoverflow/autosizing-on.png
I want to click in the middle of the Autosizing box but it does not do anything. What do I have to do in Interface Builder to make the View in a NIB to flex/stretch the view?
Usually when a view is locked down like that, it means that you have some simulated UI elements in place (like a fake nav bar, tab bar, or status bar). Select the top level view and go to the first tab of the inspector to see if any of those are turned on (you'd also see them on the view of course).
When they are all gone then you can change any of the resizing handles you like.
The view that is provided by default has this kind of limitation but you can overcome this by adding another view (you should delete the first view) to your xib and making this view the view of your file's owner. Besides this you would also have to change the height of this new view to 480 pxls.
Hope this helps.
Thanks,
Madhup