using UINavigationBar without UINavigationController - iphone

I want a UINavigationBar at the top of my UIWebView but I want to control by hand the title, the back button, what the back button does - etc. In other words I never want to push or pop views. I just want to change the UINavigationBar contents as the user clicks around the web view.
Where I'm up to is I added the UINavigationBar to my superView and made it 44 pixels tall. How do I set the title since I have no navigationItem? How would I set a fake back button up?
I would appreciate any pointers. I realise this is quite weird what I'm doing.
Thanks :)

The answer, if anyone's interested, is in the class reference of UINavigationBar.
When you use a navigation bar as a standalone object, you are
responsible for providing its contents. Unlike other types of views,
you do not add subviews to a navigation bar directly. Instead, you use
a navigation item (an instance of the UINavigationItem class) to
specify what buttons or custom views you want displayed. A navigation
item has properties for specifying views on the left, right, and
center of the navigation bar and for specifying a custom prompt
string.
In short, use a UINavigationItem and apply it by "pushNavigationItem" on the UINavigationBar.
I created a subclass of UINavigationBar called StaticNavigationBar which I can then load with any state by putting the appropriate UINavigationItem's on it. Thanks for all your answers people.

You can have that UINavigationBar as an outlet and then you can manupulate it as you want. So you don't have to refer to somebody's navigation item. It'll be an independent (sort of) object on your view.

If you dont want the navigationbar as-is youll have to roll your own.
if youre ok with the built in animations for pushing and popping items(dont confuse with push/pop of viewcontrollers) to the bar you would then set your UINavigationBarDelegate and use its methods for controlling how things push/pop, etc.

Related

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

Replacing UINavigationControllers NavigationBar with UIView

I am developing app that has multiple skins and I have a dilemma on how to implement this.
One of the solutions would be to have separate nib files for every skin, and load it depending on which skin is currently selected. Problem with this is that I can't edit navigation bar of navigation controller (which my app uses), and I have to change it's background image and back button image etc.. I came up with an idea to hide this navigation bar on every screen and replace it with custom UIView in Interface Builder which will act as navigation bar and custom back button with IBAction for popping current View Controller, so that user won't see any difference.
Is this approach acceptable and if I make it this way, will I have problems with rejection in App Store?
If you choose to hide & replace the UINavigationBar with your own UIView it's no problem as far as Apple goes.
However, I can tell you that you will have to spend some time trying to replicate some visual effects that come naturally with UINavigationBar.
For example, when you push/pop a new controller, you will see that the navigation bar title will slide & fade beautifully. The same applies for left and right bar items.
Personally I would not completely hide the UINavigationBar, but customize it. In the end it all depends on what you want, but by default the UINavigationBar is pretty customizable.
You can add your own buttons or even entire UIViews as left and right bar items. Also, you can add your own UIView as the title (with your own label, custom font or whatever) or change the background.
EDIT:
To easily customize the looks in your entire application, you can subclass UINavigationController and create your own CustomUINavigationController. Then, in viewDidLoad method you can change whatever you want to the navigation bar and this will be accessible in the entire application.
No way, what you are doing is perfect. This will work & no way it will get rejected from app store (just based on this approach). I too have explored several ways to provide skins & what you wrote seemed to be the least hassle-some. Plus its way more easier to create UI elements in Interface Builder hence the separate nib files for different skins.
I am saying this so confidently 'coz I have done the same thing & app store approved.
Best of luck.

How to programmatically adda breadcrumb view to my UINavigationController App?

I have a UINavigationController App. I want to add a small bar just below the UINavigationBar, around 20px height. y application is almost finished, so I want to rebuild as less code as possible. For example, if I wanted to add a button in the bottom of every view of my application, I can do that by extending UIViewController with a category, and adding a UIButton as a subview of the current controller view, maybe in the viewDidLoad method.
This approach works fine, and so I can add my UILabel to all my views at the top of them. The problem is that it does not TAKE SPACE. It is always on top of my previous views (UITableView...). What is the best way (or just one way) to accomplish such a thing without having to create for example a view with 2 frames, and having all my main views extending it?
I thought of changing UINavigationBar height, but that is definitely not an option.The prompt property of UINabivationBar is just to big (around 30px).
I also tried to create a new view in the viewWillAppear method of every UIViewController, adding to that view my breadcrumb subview, and the original view, but it is not working.
Any ideas on this?
Thank you!
If I were you, I'd make a new UIView subclass to represent this thing, and embed it on the views of the individual UIViewControllers. They can get at the navigation stack by looking at the UINavigationController's .navigationControllers array, walk that and get view titles, etc.

Custom UITabBarController - using a UIToolBar with UISegmentedcontrol as Tab Bar?

My customer wants a design-change, but I just can't figure out how to do this!
The app currently have a UITabBarController shifting between some UINavigationController's. My customer wants to use a UIToolBar with a UISegmentedControl shifting between the controllers instead.
I want to keep the UITabBarController, because that takes care of everything regarding loading and shifting views, but I want the UIToolBar to act as the UITabBar instead of the UITabBar!
I have allready figured out that I will need a custom UITabBarController and possibly a custom UIToolBar as well.
But I have absolutely no idea of where to start, so it would be great if somebody could give me a pointer as to where to start.
Top part to act as bottom part. http://files.droplr.com.s3.amazonaws.com/files/14763142/1g5g1s.Skjermbilde%202010-06-25%20kl.%2012.24.59.png
Thank you.
If I understand your requirements correctly, you want to have a UIToolbar at the bottom of the screen that has a UISegmentedControl that replaces pressing UITabBarItem's to switch between different views and view controllers? Assuming this is true I'd start with a custom UIToolbar class, say SegmentedControlToolbar that mirrors the basic behaviour of UITabBarController and UITabBar to add items to a segmented control, attach view controllers to each segment, and finally handle presses for each segmented control change to actually switch views.

possible to change topbar UITABLEview

Hello all what I would like to know is it even possible to change the Color of the top bar in this UITableView ( the nav + toolbar )(code wise).
http://sites.google.com/site/iphonesdktutorials/images/navtoolbar/App.jpg
Another question concerning the top bar , how do they manage to remove the backbutton
like here item 1 is the one I want to remove code wise.
http://1.bp.blogspot.com/_ixq8Dp4ESMo/Sc-qrEQzclI/AAAAAAAAAG4/EOqFoiQU9uA/s1600-h/detailview.jpg
1) Pull up the Tools->Attribute Inspector for you UINavigationBar in interface builder. Adjusting the Style and Tint attributes, among others, is the way that I have created many of my navigation bars.
2) If you would rather not see the back button, you can simply use the built in hide mechanism (from UINavigationItem reference):
setHidesBackButton:animated: Sets
whether the back button is hidden,
optionally animating the transition.
-(void)setHidesBackButton:(BOOL)hidesBackButton
animated:(BOOL)animated
Parameters:
hidesBackButton YES if the
back button is hidden when this
navigation item is the top item;
otherwise, NO.
animated YES to animate the
transition; otherwise, NO.
It would look like this:
[theNavBarItem setHidesBackButton:YES animated:false];
What's handy is that this sets a BOOL property that should keep the back bar hidden.
This is not about the UITableView but, a navigation controller.
There are many samples and guides out there on using table views in navigation controllers, including how to customize (e.g., the color of the top bar, or adding/removing/relabelling buttons).
One starting point is the apple website.
http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/UsingNavigationControllers/UsingNavigationControllers.html