how can we link UITableview in tab bar controller? - iphone

i have coded in applicationdidfinishing method in appdelegate.m file.RtbfViewController,infoViewController are UItableviewcontrolleras.but when i click HOME tab,it does not show table.what i have to do? anyone can help?
tabBarController = [[UITabBarController alloc] init];
RtbfViewController *rtbfViewController = [[RtbfViewController alloc]
initWithStyle:UITableViewStyleGrouped];
rtbfViewController.tabBarItem.title = #"HOME";
InfoViewController *infoViewController = [[InfoViewController alloc]
initWithStyle:UITableViewStyleGrouped];
infoViewController.tabBarItem.title = #"INFO";
tabBarController.viewControllers = [NSArray arrayWithObjects:
rtbfViewController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

If you haven't put any data in the tables yet, you won't get much indication of the tables being present. It's hard to tell if this is your problem or not without seeing the code for your subclasses RtbfViewController and InfoViewController.
Just in case this is your problem: You can add data to your tables by implementing the UITableViewDataSource protocol, and from there implementing at least the two required methods:
– tableView:cellForRowAtIndexPath:
– tableView:numberOfRowsInSection:
and this methods is used for grouped tables:
– numberOfSectionsInTableView:
Also, don't forget to set the dataSource instance variable of your UITableView if needed.
In general, the TableViewSuite is a useful code example from Apple for learning about the UITableView related classes.

Related

Single tab in UITabBar does not contain a UINavigationBar

I'm having a really strange issue. I've written an app with five tabs in a UITabBar. When I set the TabBarController's viewControllers property, I set it with five UINavigationControllers, so that each tab will have a UINavigationController within it.
Four of the tabs have it working perfectly. The navigation bar is there when I launch and switch to that tab. However, one of the tabs does not contain the UINavigationBar as I expected it to, and I can't understand why, because I initialized it exactly the same way I initialized all the others.
Here's some sample code from the AppDelegate.m file of initializing the individual view controllers:
SpotFilterViewController *spotList = [[SpotFilterViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:spotList];
[tabs addObject:navigationController];
[navigationController release];
[spotList release];
MySpotViewController *mySpot = [[MySpotViewController alloc] initWithSpot:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:mySpot];
[tabs addObject:mySpot];
[navigationController release];
[mySpot release];
Note: navigationController was declared above.
Anyone else run into this problem before? Or anyone have any idea why this might be happening? Any help is much appreciated. Thanks!
The problem is that you are doing this:
[tabs addObject:mySpot];
instead of this:
[tabs addObject:navigationController];

rootViewController property does not work on iOS 5 project with xcode 4.2

Hi I just started experimenting on iOS 5. I created a project without storyboard and trying to add views programmatically (no use of interface builder at all). I have following code but rootViewController property of the window does not seem to work. I did NSLog on self.tabController and it shows me value(not null) but on the other side when after self.window.rootViewController = self.tabController, i output self.window.rootViewController it gives me null in console.
I have been struggling with this issue for a long time now. Any help would be appreciated.
Following is my didFinishLaunching method:
self.dataSource = [[[ADJWebDataSource alloc] init] autorelease];
ADJBrowseListingsViewController *browseListingsVC = [[ADJBrowseListingsViewController alloc] init];
ADJSecondViewController *secondVC = [[ADJSecondViewController alloc] init];
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
navController = [[UINavigationController alloc] initWithRootViewController:browseListingsVC];
NSMutableArray* viewControllers = [[NSMutableArray alloc] initWithCapacity:2];
[viewControllers addObject:browseListingsVC];
[viewControllers addObject:secondVC];
[navController release];
[browseListingsVC release];
[secondVC release];
tabBarController.viewControllers = viewControllers;
[viewControllers release];
browseListingsVC.dataSource = self.dataSource;
NSLog(#"controller %#", self.tabBarController);
self.window.rootViewController = self.tabBarController;
NSLog(#"controller1 %#", self.window.rootViewController);
[self.window makeKeyAndVisible];
return YES;
Thanks
Vik
When you are using story board, why are you still creating objects for view controllers?
You can directly prepare the flow of your views in story board, add necessary segues etc.
If your view controller is floating (without any segues), you have to use the method "instantiateViewControllerWithIdentifier" in story board class.
For a view controller if you want to add navigation in story board, select the view controller, go to menu "Editor"->"Embed in" and select navigation controller. It will add navigation controller to your view controller.
Figured it out with the help of Firoze. Actually, I had to allocate and initialize self.window programmatically. I was confused as I never had to do that in iOS 4 or earlier. But then I just realized prior to iOS5, every project has a MainWindow.xib which had self.window allocated and initialized, now if I am not using storyboard in iOS5, there is no .xib file, I needed to allocate and initialize it myself in the code

uitabbar and uitabbaritem

I am trying to add UITabBarItems to a UITabBar not to a tabbar controller. Here is what I tried to do. It is always crashing when I am calling setItems. Can any please point out whats wrong.
My_Accounts *my_AccountsVC = [[My_Accounts alloc] init];
Payments *paymentsVC = [[Payments alloc] init];
Transfer *transferVC = [[Transfer alloc] init];
NSArray *VCArray = [[NSArray alloc] initWithObjects:my_AccountsVC,paymentsVC,transferVC, nil];
[self.tabbar setItems:VCArray];
Thanks
If you look at items, it takes an array of UITabBarItems and not UIViewController subclasses which you seem to be passing.
You will have to keep track of the view controllers elsewhere and pass an array of UITabBarItems and handle the view controllers in the UITabBar's delegate.
Or much better, use UITabBarController.
I believe you are misunderstanding how a UITabBarController works (documentation link). You must add the UIViewControllers to the UITabBarController using the viewControllers property.
The last line you have should read:
[tabBarController setViewControllers:VCArray];
The tabBar property of the UITabBarController is read-only. You cannot set that.
If you have a UITabBar (documentation link) without a UITabBarViewController, then you will need to use the method:
- (void)setItems:(NSArray *)items animated:(BOOL)animated
However, these items are not UIViewControllers! They are instances of UITabBarItem (documentation link). You may set these all at once by putting them into an array, or you can set them per view controller. There are several system items you may use (More, Favorites, etc) or you may use – initWithTitle:image:tag: to create a custom item.
Code seems wrong. I guess
[self.tabbar setItems:VCArray];
Above line should have parameter of Array of UITabBarItems. You passed items of UIViewController I guess. You should Create UITabbarItems and pass array of that in setItems method.
You should do something like below:
UITabBarItem *tabOne = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0];
UITabBarItem *tabTwo = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
NSArray *arrTabbarItems = [NSArray arrayWithObjects:tabOne,tabTwo, nil];
[tabbar setItems:arrTabbarItems];
I am not sure what it will do as I am always using UITabBarController. Hope this help.

TabViewControllers with Navigation/Tableviews reading from sql

Good Morning Guys/Girls
I am very new at programming for the iPhone, i have done alot of examples. I can create tabview project successfully and tableviews opening from SQL.
However i am finding it very difficult to try and put them all together, i am not sure i am getting the delegates very well.
I would like to ask someone if possible to please please help me with this problem to try and understand this better.
What i am trying to do exactly is have a TabView Project, each tab would have a navigationcontroller page (so a table with say search on top, and table view) the data is being populated either from sqllite3 or datacore.
Thats it.
it seems simple enough, but i am sorry, i need to see a working example to see how these multiple controllers are being loaded. Do you delegate each in a different class? please if someone can make an example to so i can load it and see.
thank you
Eden
I always prefer creating complex multiviews through coding.
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.

iPhone - Loading a new view and a deallocated object

So I feel like a serious rookie right now, but I have a problem I can't seem to figure out. I have a barebones app, with literally nothing in it except a login screen and a second view containing a tableview. When I add the second view after logging in (I have done this like 4 times before...), the table view goes through its delegates and appears that it's going to load, but something happens. I have enabled my NSZombies, and it appears to be deallocating the new view, right before it appears.
After tracing through it, and building up again piece by piece, it appears to happen after I wire the table to the view as the datasource/delegate in IB. I have set the view as a UITableViewDelegate, and the methods indeed get fired. Does anyone have any idea what might be causing this behavior?
Have you added the 'second'view to an exisitng view using addSubview: or added it to some form of UINavigationController or UITabBarController? When you do this it will automatically increase the retain count and whatever code you have releasing the view won't cause is to be deallocated.
In my AppDelegate application:didFinishLaunchingWithOptions I have something like;
LoginViewController *login = [[LoginViewController alloc] init];
[login setDelegate:self];
loginNavController = [[UINavigationController alloc]
initWithRootViewController:login];
[window addSubview:[loginNavController view]];
And then once login has occured (and succeeded using a protocol/delegate to send the message back to AppDelegate) I call this code;
UIViewController *newView1 = [[UIViewController alloc] init];
UIViewController *newView2 = [[UIViewController alloc] init];
UIViewController *newView3 = [[UIViewController alloc] init];
myTabBarController = [[UITabBarController alloc] init];
myNavController = [[UINavigationController alloc]
initWithRootViewController:newView1];
// nav controller now retaining
[newView1 release];
NSArray *viewControllers = [NSArray arrayWithObjects:myNavController,
newView2,
newView3,
nil];
[myTabBarController setViewControllers:viewControllers animated:YES];
[[myTabBarController view] setFrame:[[UIScreen mainScreen] applicationFrame]];
[window addSubview:[tabBarController view]];
// tab bar controller now retaining
[newView2 release];
[newView3 release];
// remove login from application
[[loginNavController view] removeFromSuperview];
The AppDelegate has the following declared in the header file;
LoginViewController *loginViewController;
UITabBarController *myTabBarController;
UINavigationController *myNavController;
In the dealloc method for the AppDelegate these are released.
This gives me my login page and then when that has processed my views with a top nav all controlled using the bottom tab bar.
Hope this helps in some way.
You have either too many release (or autorelease) calls - or not enough retain calls - in your view loading/transitioning code, but it's impossible to be more specific without seeing that code.
What's probably happening is the autorelease pool is being flushed between your view loading and your view being shown, and that's what's leading the behaviour you describe.