Reputation: 2210
I want to add 4 UITableViews on my scrollview and poppulate them with some different arrays(let's say i have one array for each). I have added this scrollview too to my self.view
(i do this stuff on a UIViewController class). How can i populate my Tableviews can anyone help please?
Some More Details:
here is a screen shot;
Here is the interface of my UIViewControllerClass
#import <UIKit/UIKit.h>
@interface MainMenu : UIViewController<UITableViewDelegate>
@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
@property (retain, nonatomic) IBOutlet UITableView *group1;
@property (retain, nonatomic) IBOutlet UITableView *group2;
@property (retain, nonatomic) IBOutlet UITableView *group3;
@property (retain, nonatomic) IBOutlet UITableView *group4;
@end//i drag/dropped from IB, so there is no problem with synthesizes..
I want to populate these tableview with different arrays, how to handle this situation..? Thanks a lot
Additional Note; i tried something like this but no effect:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [group1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil];
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
Upvotes: 1
Views: 310
Reputation: 1569
dude, first you will make the uiviewcontroller de delegate and data source of all 4 tables, after that you will assign a different tag for each table.. and then you will add the delegate and datasource protocols... and the you will implement the datasource and delegate methods like a normal uitableviewcontroller... all these methods receive a Uitableview parameter, so you will test the tag of this table view like:
...
if (tableView.tag == 10) {
//implement the table 1
NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil];
cell.textLabel.text = [array objectAtIndex:indexPath.row];
} else if (tableView.tag == 20) {
//implement the table 2
} else if (tableView.tag == 30) {
//implement the table 3
} else if (tableView.tag == 40) {
//implement the table 4
}
return cell;
this way you will use the same method to do all the table views..
Upvotes: 1