How to use tow UITableViews on an iPad using the same view and delegate?
If I wanna use two UITableView in the same View on the iPad, and I try to set different tag on each one.
Could I share the same delegate? Because I try to judge them by tag number, still no work.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSI开发者_开发百科nteger)section {
if(tableView.tag==0){
return [array1 count];}
else if(tableView.tag==1){
return [array2 count];}
}
or just can use one UITableView on one view?
Why not store & compare pointers of the tables
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(tableView == myTableView1){
return [array1 count];}
else if(tableView == myTableView2){
return [array2 count];}
}
Do the same in the rest of the delegate&datasource methods.
To do this, just add 2 IBOutlets in your class and connect them in InterfaceBuilder to your tables.
@property (nonatomic, retain) IBOutlet UITableView* myTableView1;
@property (nonatomic, retain) IBOutlet UITableView* myTableView2;
Just remember to release them in -dealloc:
精彩评论