How can I add 2 UITableView on 1 nib/UIView but using 2 different UITableViewController to handle ?
Thanks for helping!
Updated:
I understand the basic idea, but I just can't get it working together.
Maybe it is a simple question, but for someone doesn't know, it is obviously a difficult one.
Anyone can help trouble shooting a little bit?
I created a view based application named "MutiTableView",then drag & drop 2 TableView into the nib.
This is the generate ViewController, I add 2 IBOutlet in order to connect with 2 tables in the nib.
@class FirstTableViewController;
@class SecondTableViewController;
@interface MutiTableViewViewController : UIViewController {
UITableView *tablefirst;
UITableView *tablesecond;
FirstTableViewController *firstController;
SecondTableViewController *secondController;
}
//@property (nonatomic, retain) IBOutlet Table1ViewController *viewController;
@property (nonatomic, retain) IBOutlet UITableView *tablefirst;
@property (nonatomic, retain) IBOutlet UITableView *tablesecond;
@property (nonatomic, retain) FirstTableViewController *firstController;
@property (nonatomic, retain) SecondTableViewController *secondController;
This is how I set the datasource and delegate
- (void)viewDidLoad {
NSLog(@"viewDidLoad :(");
firstController = [[FirstTableViewController alloc] initWithStyle:UITableViewStylePlain];
secondController = [[SecondTableViewController alloc] initWithStyle:UITableViewStylePlain];
tablefirst.delegate = firstController;
tablefirst.dataSource = firstController;
tablesecond.delegate = secondController;
tablesecond.dataSource = secondController;
[super viewDidLoad];
}
This is my FirstTableViewController, it is just a basic tableViewController
@interface FirstTableViewController : UITableViewController {
NSArray *listData;
}
@property (nonatomic,retain) NSArray * listData;
@end
#import "FirstTableViewController.h"
@implementation FirstTableViewController
@synthesize listData;
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if (self = [super initWithStyle:style]) {
}
return self;
}
*/
- (void)viewDidLoad {
NSLog(@"FirstTableViewController viewDidLoad");
NSArray * array = [[NSArray alloc] initWithObjects:@"111",@"222",@"333",@"444",@"555",@"666",@"777",@"888",@"999",@"000",nil];
self.listData = array;
[array release];
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
.....
I also implemented the methods like following.
numberOfSectionsInTableView
tableView:numberOfRowsInSection:
tableView:cellForRowAtIndexPath: