1

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.

Linus Caldwell
  • 10,908
  • 12
  • 46
  • 58
sudheer
  • 418
  • 6
  • 20

3 Answers3

2

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.
}
Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90
  • It is ok for in a view controller.if viewController is initialized as tableview controller.Please check my question code.Thanks for your reply – sudheer Jun 06 '13 at 12:34
0

I think you have not searched well.

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

Community
  • 1
  • 1
Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39
0

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...

Jabson
  • 1,585
  • 1
  • 12
  • 16