How to create UITabviewcontroller with Frame - ios5

i have a code for UItabviewcontroller using programmatically ,but how to creates its frame as i am using as subviews in my application where i required x,y width and height coordinates.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
UIViewController *vc1 = [[UIViewController alloc] init];
UIViewController *vc2 = [[UIViewController alloc] init];
UIView *v1 = [[UIView alloc] init];
UIView *v2 = [[UIView alloc] init];
vc1.title = #"vc1";
vc2.title = #"vc2";
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];
self.view = tabBarController.view;

As you tagged your question with ios5, I suppose your app is only running on ios5. If I understand you right, you want to present the tabBarController in another view controllers view.
Prior to 5.0 this is not possible, without some very ugly hacks. But with iOS5.x there now is an API for that. Take a look at the UIViewController documentation at 'Implementing a Container View Controller'. You have to set the tabBarController as a child view controller of your current view controller. Than you can assign the frame you want it to have and simply add it to your View.

Related

How can i take a UITabbar in a viewController?

If i go straight to the point then my problem is i have an UIViewController with two button.
Button One --(onclick must navigate to)--->UITabbarController with 4 UITabbar item or i can take a UITabbar in my new UIViewController;
Button Two --(OnClick must navigate to)--->UITabbarController where first tabbaritem will contain containing UITableView or or i can take a UITabbar in my new UIViewController where first TabbarItem will contain a UITableView.
How can i make this??? sample code will more helpful neither suggestion. if you need any clarification please do not hesitate to ask.
With Best Regards
Emon
First, you need to have a NavigationController if you want another view controller to be pushed on when you click a button. The steps you would need to do are the following
Start with a MasterDetail app on iPhone
In the xib file, put your buttons and wire them up to the correct methods
In the view did appear of the view controller have the following code
self.tbc1 = [[UITabBarController alloc] init];
self.tbc2 = [[UITabBarController alloc] init];
UIViewController *tbc1vc1 = [[UIViewController alloc] init];
UIViewController *tbc1vc2 = [[UIViewController alloc] init];
UIViewController *tbc1vc3 = [[UIViewController alloc] init];
UITableViewController *tbc2vc1 = [[UITableViewController alloc] init];
UIViewController *tbc2vc2 = [[UIViewController alloc] init];
UIViewController *tbc2vc3 = [[UIViewController alloc] init];
[self.tbc1 setViewControllers:[NSArray arrayWithObjects:tbc1vc1,tbc1vc2,tbc1vc3, nil]];
[self.tbc1 setViewControllers:[NSArray arrayWithObjects:tbc2vc1,tbc2vc2,tbc2vc3, nil]];
Ofcourse you have to have properties defined for tbc1 adn tbc2 in your view controller.
In the app delegate do the following
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *myViewController = [[ViewController alloc] init];
self.viewController = [[UINavigationController alloc] initWithRootViewController:myViewController];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Change the UIViewController in the .h file to UINavigationController like
#property (strong, nonatomic) UINavigationController *viewController;
Have the two buttons and wire it to the following methods
-(IBAction)tbc1Clicked{
[self.navigationController pushViewController:self.tbc1 animated:YES];
}
-(IBAction)tbc2Clicked{
[self.navigationController pushViewController:self.tbc2 animated:YES];
}

Problems with UINavigation controller inside of UITabbarcontroller

I have an UITabbarcontroller with 4 tabbar items.Each tabbar items have UINavigationController.Actually Tabbar loads the last view controller from stack while i switch next tabbar item.
I want to load the first view controller from the stack whenever i switch between the tabbar item.
How can i achieve this?
You want it to go back to the root view controller within each tab, rather than remembering where in the hierarchy the user was, whenever you switch tabs?
You need to call popToRootViewControllerAnimated:NO on the navigation controller as you switch tabs (i.e. in a tab bar controller delegate method).
The best approach you may follow is :
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthsize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.
Hope this helps.

show always a uiimage on the top of a tabbar

i searched before post my question, but i find nothing useful.
before: i'm a c# developer and i'm doing my first iphone app, don't kill me please!
in my app i have a tabbar controller on the bottom (4 buttons)
each button, is a navigation controller type, its show a navigation bar on the top and in the middle i have a viewcontroller (normally after i load an uitableview)
the mad person that asked me to do this app wants that in the top of the TabBar to show always an image (for advertisement, fixed as 320x50).
so the app should look in this way
< NavigationBar >
ViewController
< UIImage >
< TabBar >
but now is
< NavigationBar >
ViewController
< TabBar >
at first take tabbarview controller then make view controller then set the UIimage then set the navigation bar for the uiview controller
NSMutableArray *listOfViewControllers = [[NSMutableArray alloc] init];
dashBoardView = [[DashboardViewController alloc] initWithNibName:#"DashboardViewController" bundle:nil];
dashBoardView.title = #"dashBoardView";
UINavigationController *mydashboarController = [[[UINavigationController alloc] initWithRootViewController:dashBoardView] autorelease];
mydashboarController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:mydashboarController];
[dashBoardView release];
ordersView = [[OrdersViewController alloc] initWithNibName:#"OrdersViewController" bundle:nil];
ordersView.title = #"ordersView";
UINavigationController *myorderController = [[[UINavigationController alloc] initWithRootViewController:ordersView] autorelease];
myorderController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderController];
[ordersView release];
orderList = [[OrderListViewController alloc] initWithNibName:#"OrderListViewController" bundle:nil];
orderList.title = #"orderList";
UINavigationController *myorderListController = [[[UINavigationController alloc] initWithRootViewController:orderList] autorelease];
myorderListController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderListController];
[orderList release];
[self.tabBarController setViewControllers:listOfViewControllers animated:YES];
i think it will help you some way...

Complex multiview iphone ios

i need to implement a multiview app really complex to me and i need some advice. The multiview app is something like:
First view: Normal UIViewController with one button, when i push it go to second view
Second view(aka mainview): a Windows with Tab Bar with 2 tabbar item who switch between:
Second view A: Normal UIViewController with some elements
Second view B: UITableViewController
Can someone give me an advice where to start reading or some examples?
thx
my advice is to read sample code form apple there you can also find coding how to s so good luck, or you can find example codes all over the stack just search. for example navigation based app:
UINavigationController doesn't work in a the moreNavigationController of a UITabBarController
or simple transition:
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
hope it helps bye
wblade
You need to start with view based application. And then create a UITabbarController in you appDelegate file.
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthsize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.

UITabBar with UINavigationController in code

I've currently got a UITabBar with 5 screens calling UIViews. That part works fine but I want to put in a UINavigationController in a couple of them. I have found a few tutorials that work fine but all of them implement it in IB and I want to avoid that if possible.
I'm lost as to where to implement the UINavigationController, should I do it in the App Delegate with the UITabBar and call the navigation controller from the UIView or should I create it in the UIView class?
I've tried about 8 different ways and always ends up with either the Navbar not working, no nav bar at all or the app crashing.
Currently I create the tab bar like this:
tabBarController = [[UITabBarController alloc] init];
ScreenA *screenA = [[ScreenA alloc] initWithNibName:#"ScreenA" bundle:nil];
//more here
tabBarController.viewControllers = [NSArray arrayWithObjects:screenA, ...., nil];
[window addSubview:tabBarController.view];
And in the initWithNibName I have this:
self.title = #"Screen A";
self.tabBarItem.image = [UIImage imageNamed:#"someImage.png"];
Ok, do it like this...
tabBarController = [[UITabBarController alloc] init];
searchTableViewController = [[SearchTableViewController alloc] init];
UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release];
searchMapViewController = [[SearchMapViewController alloc] init];
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release];
tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, nil];