sudheer
sudheer

Reputation: 428

How to add multiple tables in UITableViewController

Any one please tell me how to add two tables in uiview controller? I created a class object in rootviewController as

mainDataViewController=[[MainDataViewController alloc]initWithStyle:UITableViewStylePlain];

And in mainDataviewController taken as UITableviewController

@interface MainDataViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate>

Now, I Want to add three tables in mainDataViewController.

Please give me some idea for solving this.

Upvotes: 1

Views: 884

Answers (3)

Prince Kumar Sharma
Prince Kumar Sharma

Reputation: 12641

follow these steps.

1)Create a tableViewController with xib. 2)Create only two other xib's as given screenshots below:--

enter image description here 3)Drag uitableView from object window.

enter image description here

4)Change its class to TableViewController's class you have firstly created.

5)Connect file owner's view delegate to tableView.

6) And use code as ------

- (void)viewDidLoad
{
    MYViewController *FirstTableController=[[MYViewController alloc] initWithNibName:@"MYViewController" bundle:nil];
    MYViewController *secondTableController=[[MYViewController alloc] initWithNibName:@"MYSecondController" bundle:nil];
    MYViewController *thirdTableController=[[MYViewController alloc] initWithNibName:@"MYThird" bundle:nil];



    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

enter image description here

Or

#import <UIKit/UIKit.h>

@interface MYViewController : UITableViewController
{
   IBOutlet UITableView *f_table,*s_table,*t_table; //outlets for different tableViews in xib.
}

@end

enter image description here

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view=f_table; // when working with first table.

    self.view=s_table; //working with second table.

    self.view=t_table; //working with third table.
}

Upvotes: 2

Jabson
Jabson

Reputation: 1703

1) First add tableview on your viewController xib file

enter image description here

2) declare variables for your tableviews

enter image description here

3) synthesize properthies

enter image description here

4) add outlets to your propethies

enter image description here

Now you can use them...

Upvotes: 0

Piyush Dubey
Piyush Dubey

Reputation: 2414

I think you have not searched well.

Please have a look at this. How to use 2 UITableView in a UIViewController?

Upvotes: 0

Related Questions