Reputation:
Expecting your well advice!
I have a TableView(Grouped Table created via I.B). I'm showing some data on the table when code executes using Navigation Controller view. I want to add a "Tab Bar" in my Table view whether through I.B (or) Programmatically. For ex: Launch built-in "Clock" app, where you can see a Tab Bar which has options of 'World Clock', 'Alarm', 'Stop Watch' and 'Timer' in single view itself. I tried to create like same by adding a 'Tab Bar' in I.B, but drag and drop of Tab Bar doesn't sit in the Table View. I don't know why. (or) else i even tried programmatically to create it in the Table View, but not succeeded. Is it not possible? Can anyone please help me on pointing out the code or samples?
thanks.
Calve/
Upvotes: 0
Views: 2997
Reputation: 91
You need to add it to your parent controller's view. Also the tempView element is not necessary.
E.g. if the app uses a navigation controller as the main view controller you would add this to your custom UITableViewController class:
- (void)viewDidLoad
{
[super viewDidLoad]; UITabBar* tabBarView = [[UITabBar alloc] initWithFrame:CGRectMake(0, 430, 320, 50)];
NSArray* tabbarItems = [[NSArray alloc] initWithObjects:[[UITabBarItem alloc] initWithTitle:@"Item1" image:nil tag:1],[[UITabBarItem alloc] initWithTitle:@"Item2" image:nil tag:2],[[UITabBarItem alloc] initWithTitle:@"Item3" image:nil tag:3], nil];
tabBarView.items = tabbarItems;
[self.navigationController.view addSubview:tabBarView];
}
Upvotes: 2
Reputation: 12409
I think you are taking the wrong approach. Adding a tab bar to your table view is wrong. You are supposed to start with the tab bar app and add a navigation controller to that tab bar app. Inside the navigation controller you can add a view with a table on it.
Upvotes: 1
Reputation: 11231
Try creating a UIView and adding a tabBar to that view, and now place this view inside your table. I tried this and its working,
So your function cellForRowAtIndexPath will look like this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
UITabBar* tabBarView = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
NSArray* tabbarItems = [[NSArray alloc] initWithObjects:[[UITabBarItem alloc] initWithTitle:@"Item1" image:nil tag:1],[[UITabBarItem alloc] initWithTitle:@"Item2" image:nil tag:2],[[UITabBarItem alloc] initWithTitle:@"Item3" image:nil tag:3], nil];
tabBarView.items = tabbarItems;
[tempView addSubview:tabBarView];
[cell addSubview:tempView];
return cell;
}
So now instead of using default cell you can customize it to the way you want.Also I havent considered memory release issue so u might need to update the code to release the allocated memory.
Upvotes: 0