我在类中的tableview有这些委托方法:
@H_404_2@- (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 = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier] autorelease] ;
}
cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
return cell;
}
解决方法
看看所有委托方法如何在其中包含tableView:(UITableView *)tableView?
您可以在头文件中定义表视图,然后只需执行:(假设您的表名为myTable)
@H_404_2@if (tableView == myTable)然后,您可以拥有任意数量的表视图.
例如:
@H_404_2@- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array1 count]; }变为:
@H_404_2@- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == myTable) { return [array1 count]; } if (tableView == myTable2) { return [array2 count]; } return 0; }