Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在同一个tableView中同时显示两个功能不同的单元格?_Ios_Swift_Uitableview_Tableviewcell - Fatal编程技术网

Ios 如何在同一个tableView中同时显示两个功能不同的单元格?

Ios 如何在同一个tableView中同时显示两个功能不同的单元格?,ios,swift,uitableview,tableviewcell,Ios,Swift,Uitableview,Tableviewcell,我有桌面视图 我有一张桌子。TableViewCelone允许用户输入文本和图像,并保存在数据库中。这部分很好用 我想构建tableViewCellTwo。这两个细胞的功能不同于塞隆。cellTwo将检索并显示此数据 我希望两个单元格同时可见。在同一个tableView上,上面是tableViewCellOne,下面是tableViewCellTwo。下面是我编写的代码的相关部分。从目前的工作方式来看,它只显示tableViewCellOne,这不是我的意图。这段代码是在我的TableViewC

我有桌面视图

我有一张桌子。TableViewCelone允许用户输入文本和图像,并保存在数据库中。这部分很好用

我想构建tableViewCellTwo。这两个细胞的功能不同于塞隆。cellTwo将检索并显示此数据

我希望两个单元格同时可见。在同一个tableView上,上面是tableViewCellOne,下面是tableViewCellTwo。下面是我编写的代码的相关部分。从目前的工作方式来看,它只显示tableViewCellOne,这不是我的意图。这段代码是在我的TableViewController中编写的

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
      // Table view cells are reused and should be dequeued using a cell identifier.

     if (indexPath.row == 0) {

      let cellIdentifier = "MyTableViewCell"
      let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MyTableViewCell

        // Fetches the appropriate data for the data source layout.
        let data = myData[indexPath.row]
        cell.MyData1.text = data.1
        cell.MyData2.image = data.2
        cell.MyData3.text = data.3
        return cell

     } else {

      let cellIdentifier = "TheirDataTableViewCell"
      let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! TheirDataTableViewCell

        // Fetches the appropriate data for the data source layout.
        let data = theirData[indexPath.row]
        cell.TheirData1.text = data.1
        cell.TheirData2.image = data.2
        cell.TheirData3.text = data.3
        return cell
    }
}
通过这个if-else语句,我试图说:当我们加载单元格1时,然后加载以下数据,当我们加载单元格2时,然后加载以下其他数据。但我认为它的解释是:如果(某物)装入单元格1,如果(某物)装入单元格2。不过,我的诊断可能有点离谱


如何在同一个表视图中同时显示两个功能不同的单元格?

表视图(\uuuu:numberofrowsinssection:)
中返回什么?这是一个很好的问题。我编写了[ReturnMyData],这是一个数据模型。但是我没有返回theirData数据模型。它说,在我返回第一个后,之后的任何代码都不会被读取,因此我不知道如何返回两者。您必须返回一个
Int
。当您返回其他内容时,编译器应该警告您。实际上,在您的情况下,在numberOfRowsInSection中,您应该返回2。至于其余的,在tableview中显示混合类型的单元格没有问题,看起来您做得不错。