I have two instances of UITableView in one app, and the problem is that I don’t know how to define what each table needs to display. Here’s the code:
.h :
{
NSArray *array1;
NSArray *array2;
IBOutlet UITableView *table1;
IBOutlet UITableView *table2;
}
.m :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array1 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
}
This code is working for just one table. I don’t know how to set up the other table with array2. Have you got any ideas, people?
All you need to do is check which
UITableViewyou are setting up in thedelegate/datasourcemethods. Try:Hope that Helps!