Where to write in viewcontroller using UITabBar - iphone

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 :)

Related

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

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

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

PullRefreshTableView editing

I have a PullRefreshTableView from leah(https://github.com/leah/PullToRefresh). Problem with this, as soon as I implement this. The view is changed to a tableview by doing this:
#interface news : PullRefreshTableViewController {
So I can't add any toolbars or navigationcontrollers to the top. Does someone know how I can add a toolbar to the top of the screen in combination with the PullRefreshTableView.
Thnx!
You know when you have this standard UINavigation template when you create a new project with xcode? Gives you 3 ( right ? ) nib files, 1 with the window, 1 with the mainview / navigation controller and the other one contains the tableview.
Open the one with the tableview. Select the tab that looks like this:
It will allow you to change the class it creates when the nib file is loaded. Change it to the PullRefreshTableView and when you launch the application a PullRefreshTableView will be created instead of a normal table view.
You can hook this up as an Interface Builder outlet exactly the same way you would hook up a normal table view. Its a subclass so it should even be able to be connected to the normal tableviewcontroller that is included in the template.
If you have done this, you should still be able to add the toolbars like you did with a normal table view. Also, if you want to have a toolbar on your iphone screen it shouldn't be a subview of the Tableview, but a container view should contain both the toolbar and the tableview.

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!

Adding new views to a window / changing view

I asked a question on here last week and I have tried to follow examples but not having much joy,
So I am trying to create a app that will have a main window. In this window I want to be able to display 3 or 4 different views (not at the same time) which the user can select the view via a button press. I did not want to use a navigation bar if possible.
am I right in thinking that I will need
View1 .h &.m
View1controller .h &.m
and the same for the second etc
Now if the button to select view 2 is on view 1,
how do I change the view and where do I put this code?
Do I need a root-controller or am i getting confused with other ways of doing the same thing.
Thank you in advance for your help.
If you want to change between the views like in the iPod application, you can accomplish this with a UITabBarController. You would create all the view controllers, and add then to a root tabbarcontroller. The tabbarcontroller then serves to automatically switch between views for you when the button is selected.
If you have a view with a button on, and want to change the active view u can use this method from UIViewController of the active view:
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;