In which method should I set my UIToolBar hidden - iphone

I have been coding in iphone platform for about a few months. One thing I am still to understand is in which method exactly should I set the navigation bar/toolbar/barButtonItem hidden.
In my project sometimes I set in - (void)viewDidLoad, sometimes I set in - (void)viewWillAppear:(BOOL)animated. Sometimes I set it from where I push the navigation controller.
I think I am not understanding the basics correctly. If one way is not working, I try the other way and somehow it works.
If I am to hide the toolbar or barbuttonitem in navigation controller, where exactly should I set that.
Edit:
If I am pushing a new navigation controller, in which I want my toolbar hidden, where should I set it hidden. Similarly, when I pop it, I want the the toolbar to be shown, where should I set the toolbarHidden property to 'NO'.
Similarly, I have a navigation controller, sometimes it needs to show the toolbar and sometimes it needn't, where should I check the condition for this case.?

You should set this property before the pushing the view Controller and don't need to set No at pop. E.g see the following link:
hiding tabbar on table view cell click

Related

iOS 6.1 Table View Screen Footer

My iPhone app starts off (using a storyboard) with a navigation controller, then a table view controller; what I want to do next is use a tool bar to provide options to go to other table view controllers. The problem is that the tool bar is buried off screen. I would like it to be more like a screen footer, always visible to the user. What is the best way to do this?
The toolbar was originally added to the tableview so as the list got longer the toolbar showed up at the end of the list hidden off the screen unless you scrolled down.
To fix this problem in the Attributes section of the Navigation Controller in the Simulated Metrics I set Bottom Bar to Toolbar. I then did the same thing in the Table View Controller. I then added the Bar Button Items to the toolbar on the Table View Controller.
Then I had to control where the toolbar appeared downstream by calling
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.toolbarHidden = YES;
}
in the applicable table view controllers and setting YES or NO.
For some reason I was unable to find good documentation for this process. It probably is out there, but I have included it here for others who may have this problem.

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

How to disable backBarButtonItem displayed in current view?

After a view has been pushed onto the UINavigationController stack and is displayed I need to disable the Back button under certain circumstances, e.g., when data is being edited on that screen.
The following hides the Back button
self.navigationItem.hidesBackButton=YES;
but I need to disable it.
There are several other answers about how to hide it or suggest not displaying it in the first place, but these are not what I need to implement.
You could implement one of the delegate methods for your navigationController's navigation bar delegate. Take a look at the [UINavigationBarDelegate navigationBar:shouldPopItem:] method.
Returning YES or NO from this method will enable or disable the back button.
You could implement one leftBarButtonItem (invisible and without effect)
add it into your current view (self.navigationItem.leftBarButtonItem)
and remove it to access your backButton.
If you're fine that the whole navigation bar is disabled, an easy solution is
self.navigationController.navigationBar.userInteractionEnabled = NO;
Of course this doesn't work if you have other bar buttons that you want to keep enabled.

iPhone Objective-C: Programmatically change title of tab bar item in tab bar created using IB?

Right now, I am setting the title in the viewDidLoad of the root view of the tab, which only changes when I click on the tab. I want this to be set before I select the tab. I tried something like:
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:2] title] = #"string";
in the first view that loads in another tab, but there is clearly something wrong since I get a left operand error.
What is the correct way to achieve what I am trying to do?
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:2] title] = #"string";
The syntax is slightly off here. You probably wanted something like:
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:2].title = #"string";
However, that won't work, since there is no title property to set. In fact, there's no way I can see to change a UITabBarItem's title once it's been initialized. You'll have to use UITabBar's setItems:animated: method to set the entire group of items at once. But it won't be fun.
I bet this would be an Apple HIG violation, which is why there's no easy way to do it with the current API. Rethink your design and ask yourself why you want to change the names of the tabs, which will confuse your users.
Try setting the title in awakeFromNib instead of viewDidLoad. The view for a view controller is not actually loaded until you need the view, and the tab bar controller by default doesn't access the view of a view controller until you actually select it (which is why you saw the title change when you selected the tab).
Since the nib is creating the view controller to start with (assuming you have built your tab bar controller in IB) awakeFromNib will be called as soon as the view controller has been built, before the tab bar controller can ask what the title is.

Current UIView Questions iPhone SDK

I posted earlier but am running into similar problems again. Basically the way that my app is setup there is a top bar that is basically just a static image that has UIButtons placed on top of it. That is the Main View Controller and is persistent no matter what view is shown beneath it. I can't use a navigation controller because it is not possible to change the height and I need the bar to be significantly larger than a navbar. However my bar is functioning in much the same way. There is a "Home" Button, a "Back" Button and several destination buttons.
I understand how to switch views from say the home screen. My confusion comes with the back button. In order to press back the app is going to need to know what view is currently being displayed so that it can be removed from view and a new subview can be added. Ideally I would use the UINavigationController so that I can push and pop views which is really what I want to do here, however that is not possible because of the visual problem.
Does anybody know of a method that returns the current displayed view so I could do something like the following
[currentview.view removeFromSuperView];
[self.view insertSubview:experienceViewController.view atIndex:0]
You can use UINavigationController with the nav bar hidden. Put the nav controller inside a view that does have your jumbo toolbar and you'll have access to the push/pop behavior you're looking for.