目标C-iOS多个表格视图

use*_*398 0 uitableview ios

我正在尝试编写一个连接到我的Web服务并在表视图中显示数据的应用程序。我也有一个菜单的静态表格视图。静态表格视图有效(响应单击,显示选项等),但我为使第二个表格视图正常工作而感到困惑。每个窗口最多只能有1个表格视图。我将添加大约10个表视图。

静态表视图的代码:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"dataSelect"; //Name of table view


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

tableData是我要插入的数组。

ldi*_*ndu 6

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"dataSelect"; //Name of table view

    if (tableView == tableview1) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        }
        cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    } else if (tableview == tableview2) {   

        // do actions related to tableview 2 here

    } else {

         // and so on
    }   
Run Code Online (Sandbox Code Playgroud)

}