ios - Objective C - iOS 多 TableView

标签 ios uitableview

我正在尝试编写一个连接到我的网络服务并在表格 View 中显示数据的应用程序。我还有一个菜单的静态 TableView 。静态 TableView 有效(响应点击、显示选项等),但我很难让第二个 TableView 正常工作。每个窗口不超过 1 个 TableView 。我将添加大约 10 个 TableView 。

静态表格 View 代码:

- (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;
}

tableData 是我要插入的数组。

最佳答案

- (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
    }   

关于ios - Objective C - iOS 多 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17380273/

相关文章:

ios - Swift TableView 不显示 Nib 中的任何内容

android - 如何在点击文本时更改文本的颜色和/或装饰

iOS谷歌VR SDK : Unable to preview Video

swift - 如何区分位于 2 个不同类的 TableView

ios - 在点击 UITextField 时显示 UITableView

ios - iOS5 上的 FBConnect 和 ARC

javascript - 检测 JSContext 中的错误

iphone - UITableView 已加载(完成绘制单元格)

swift - swift 从 do-catch 语句中获取变量

ios - UITableView 中的 UITextField 没有成为第一响应者