I have a main navigationController controlled on the app's delegate and this navigationController contains a RootViewController.
Inside this view controller I have defined a UISegmentedControl that is assigned to the toolbar, using something like:
[self.navigationController.toolbar addSubview:segmentedControl];
this segmentedControl has 3 segments, each one pushing a viewController.
The problem now is this: I want to show a view that will contain an iAd or AdMob ad and this view must be always be visible independently of which segmented is pushed by the segmentedControl.
Is it possible to add a view that is somehow on front of the segmented control and is not affected by the controls it pushes on screen? thanks
Another option would be to not use a NavigationController - don't navigate - make the toolbar and the ad view space stable and swap out the contents.
That option would have a standard UIViewController with a UIToolbar at the top containing the segment control. Below that would be an addView and below that would be a content view where you could swap out views or layers based on the segment control selection.
That access pattern might not be appropriate for your app and data patterns but it does have the benefit of not navigating/pushing a completely new viewController.
From the UIView Programming Guide:
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html
... transitionFromView:toView:duration:options:completion: methods to
swap out entire sets of views for new ones.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/transitionFromView:toView:duration:options:completion:
Related
I want to duplicate this controller same functionality without using it, this is because tab bar controllers are not customizable at all (fixed size, toggleable state tabs, etc...).
I want a customized "tab bar" that contains whichever view I want. And also I need to push view controllers leaving this customized tab bar fixed in its position.
I´ve seen lots off apps that do this, and I was wondering if using different UIWindow objects (one for the custom tab bar and other one for the content) was the best approach.
Any advice or guidance on this?
Thanks in advance.
Definitely not UIWindows - in an iPhone app there should only ever be one UIWindow.
I'd make a UIViewController subclass that had your new navigation bar ui at the top and a UIView underneath it. This view would be used to contain all the views of the controllers you are going to push in it. The view would have clipsToBounds set to YES to make sure your other controllers views don't overlap your navigation bar etc.
It would also have an array to hold the list of controllers that are currently inside it.
Your controller would implement the pushViewController:animated: methods etc to allow you to add other view controllers to the stack - you would add the new controller to your array and would add it's view as a subview of your controller's view.
However, it's actually quite a lot of work to make this well - a navigation controller will release child controller views on low memory warnings, handle rotation, animating on/off views etc. Are you 100% sure that this is what you want to do?
I've used a very simple approach. I subclass UITabbarController and during the init:
// Custom TabBar View
//
self.tabBar.hidden = YES;
MyTabBarView *myTabBarView = [[MyTabBarView alloc] initWithFrame:CGRectMake(0, 1024-44, 768, 44) // it'a an iPad app
configuration:configuration]; // an array of dictionary representing the view controllers
[self.view addSubview:myTabBarView];
[bottomBarView release];
then I load some view controllers with:
aViewController.hidesBottomBarWhenPushed = YES;
From MyTabBarView instance I perform on the UITabBarViewController:
setSelectedIndex:
In this way I've a customizable full screen application without pains.
Alright, this seems simple enough but I haven't found much documentation or posts regarding this. Basically, I want to have a completely custom tab bar at the bottom of my app. Being new to iPhone dev I thought I could do the following:
Place custom images on bottom of
screen to act as tab buttons.
Create a UIView (lets call it
"ContentView") to fill the rest of
the screen that will display the
appropriate tab's NIB. This
"ContentView" is inside the main
UIView for the NIB.
Hook up image "press" actions to the
controller managing all this.
I'm not sure how I would go about loading the appropriate NIB into the "ContentView" with this method though. From the "Touch Up" action method in the controller can I dynamically load a NIB into that "ContentView" UIView?
Something about this whole thing makes me uneasy.
Is there a better way?
To solve your problem I would create a nib with a UIView and its associated content in it. Connect the nib to a UIViewController. This will be the content of each tab. Create as many of these UIView-UIViewController combination as needed.
When the user touches a tab, create and load the UIViewController from the nib using
– initWithNibName:bundle:
Add the UIView in the nib to the main content view as a subview. Use
– addSubview:
As the user presses other tabs load the other nibs into memory and add their UIView into the main content view as a subview.
If a view is already in memory you can show and hide subviews with the following methods.
– bringSubviewToFront:
– sendSubviewToBack:
I think that would work.
You can solve this by,
either make different views with same tab bar image and custom button(load view on IBAction for button click:toucp up inside) or you can make different views for the same view(so you can hide views and show only one view at a time accordingly).
and you can load view (if you app is view based then add other views on window otherwise for navigation based app you need to pushViewController of navigation controller.
This is a tricky task but you need to handle this.
I'm getting confused on view controllers and would love a straight example. Here's the preamble:
I have a UIViewController with a matching .xib.
By default IB gives me a single View in the Document window.
I can make it appear by telling my UIWindow to addSubview:controller.view and bringSubviewToFront:controller.view
Here's the questions:
Should I add another View to the ViewController in IB? Or is there a better, programmatical way?
How do I tell the ViewController to switch between the Views?
From the ViewController downward, what does the code look like to achieve this?
I'm trying things but just making a mess so I thought I'd stop and ask...
Note that every button, label, image, etc. in your main view controller is actually a view in itself, however I've interpreted your question to mean that you want to manage multiple full-screen views or "screens". Each screen should have its own view controller to manage it. So to get the terminology right, a view-controller is an object that manages a single full-screen view (or almost full screen if it's nested inside a navigation controller or tab bar controller for example) and a view is the big area managed by the view controller as well as all the sub-views (images, buttons, labels, etc.) within it (they are all UIView sub-classes). The view controller manages all of them on that screen, if you want another screen/page then you should create a new view controller to manage it.
The root view controller (the one you add to the window) can be a plain old normal view controller that you've designed in IB, however it's probably more useful if you use a navigation controller or a tab bar controller and add your designed view controller to that - then you can push additional view controllers as needed.
Another way (if you don't want navigation or tab-bar style) would be to transition to other view controllers directly in the main window using whatever transitions you like (or just replace the old one). We'll leave that for now though.
Any sub-views of your main view controller (the one you've designed in IB) will be automatically loaded from the nib file, but you can also add your own views programatically if you want (typically you would use one or the other, i.e. nibs or programatically, but you can mix and match if you want). To do it programatically, override loadView in the view controller and then call [super loadView]; then do [self.view addSubView:myOtherView]; (create the myOtherView first of course). Note that the first time .view is accessed on your view controller, it actually calls loadView to create the view, so inside loadView it's important to call [super loadView]; before trying to access self.view :D
To switch between views, using the navigation or tab bar controllers makes it very easy. So put your main view controller inside (for example) a navigation controller and put the navigation controller in the window, so you've got window->navigationController->myController. Then from an action method in your view controller (you can hook up the action methods in IB), for example when an "about" button is pressed do this:
- (void)doAbout
{
// Create the about view controller
AboutViewController* aboutVC = [AboutViewController new];
// Push the view controller onto the navigation stack
[self.navigationController pushViewController:aboutVC animated:YES];
[aboutVC release];
}
Note that the about view controller is created programatically here - if your about view is designed in IB then instead use initWithNibName:bundle: to create it.
And that's how you manage multiple screens.
I have a tabbar application. Second tab had a drill down table list with Navigation Controller. I also want to implement a segmented control inside a tool bar that shows different table entries as per the selected switch in segmented control. I am a little confused as to how to implement this?
Screen-shot -
This is the view in second tab controller an instance of the generic UIViewController. Blue Background is a UIView that contains a segmented control (1,2,3,4). The steel blue navigation bar at the top is a simulated UI Element from Interface Builder. I need to put a navigation Controller such that it has a list table view that changed depending on the switch selected in segmented control UI.
I have following options
Add UINavController as root controller for second tab directly with table view inside it. In that case how do I accomodate the UIToolbar having segmented control?
I add UISegmentedControl as part of the view of Second Tab's view controller and add navigation based table view as another element to that view. Is this doable? How can I add a nav based controller to a UIView and control the frame so that it does not cover the UIToolBar.
I hope I am making sense. Please lemme know if you have any suggestions. Thanks.
This is how I achieved it. In IB, in MainWindow.xib where I have a tabbarController, I made the class identity of the second tab to a UINavigationConrtroller. Then I made the main view Controller for second tab that had the segmented control and the Table View as a rootViewController to the NavigationController. This functioning exactly as I wanted. Thanks all for your help.
you can add UINavigationController in place of UIViewController in UITabbarcontroller and Put your UIViewController who haveing UISegmentControl in UInavigationController who add in UITabbarcontroller
in reading its looks confusing but try to implement its work
Step 1: xcode-->new Project-->tabbar application
Step 2: open xib of main window select tabbarcontroller and open inspector. in that you able to see list of view controllers change their class to uinavigationController.
if you need uinavigationController in second tab then change only secong tab class to uinavigationController
step 3: create new uiviewcontroller. open its xib and add uitableview and segment control to that.
Setp 4: now expand tabbarcontroller and check your second tab have navigationcontroller now add your uiviewcontroller in navigationcontroller's viewcontroller
According to your requirements you can't avoid working with code - I mean that you can't set everything by connections in IB.
I would create a UIViewController (let's call it container) that will contain the segmented control and the navigation controller.
You should set the second tab to be a view controller and point it to the container.
Container's view (XIB if you want) should contain the segmented controller that will be aligned to bottom and a containerView that will fill the rest of the view and will have its IBOutlet.
Container should also have a navigation controller member that will be initiated in viewDidLoad.
The table view that you talk about should also be built in its own XIB and have its own view controller that will be set as root view controller to the navigation controller...
Tell me if it's too confusing / complicated...
I have created an iPhone application based on an OpenGL view. Now I
would like to show a "settings" form. Since my code runs in UIView, I have no pushViewController. How do I show a view controller on screen?
Thanks!
You can do this in one of two ways:
You can create a new view hierarchy, and then add it as a subview of your UIWindow when you want to show preferences. When you're done with your prefs, you can animate it out and then remove it as a subview.
You can switch to a UINavigationController/UIVIewController based hierarchy, and hook your current OpenGL/UIView to a UIViewController's view outlet. Then you can use all the regular UINavigationController based navigation stuff.