iOS-UITableView将单个静态单元格添加到动态表

iOS-UITableView将单个静态单元格添加到动态表,ios,objective-c,iphone,uitableview,nsfetchedresultscontroller,Ios,Objective C,Iphone,Uitableview,Nsfetchedresultscontroller,我有一个UITableView,它由NSFetchedResultsController控制。我想将单个单元格添加到第一行,并使此单元格成为静态单元格。换句话说,将有一个按钮打开另一个视图控制器 到目前为止,我对获取的结果控制器和表还可以。现在我有点糊涂了。我该怎么做 相反,使用标题也可以,但我不希望这个标题一直在顶部。我希望这个单元格就像聊天面板上的WhatsAppiOS“createnewgroup”单元格一样 谢谢大家! 您需要使用从NSFetchedResultsController获取

我有一个
UITableView
,它由
NSFetchedResultsController
控制。我想将单个单元格添加到第一行,并使此单元格成为静态单元格。换句话说,将有一个按钮打开另一个视图控制器

到目前为止,我对获取的结果控制器和表还可以。现在我有点糊涂了。我该怎么做

相反,使用标题也可以,但我不希望这个标题一直在顶部。我希望这个单元格就像聊天面板上的
WhatsApp
iOS“
createnewgroup
”单元格一样


谢谢大家!

您需要使用从NSFetchedResultsController获取的行数+1来创建tableview。同样在
cellForRowIndex
方法中,您需要添加一个类似
indexPath.row==0的检查,并在其中进行更改

您还必须在该部分中为该按钮添加操作。您还可以为第一行设置不同的自定义
tableview
。 它可以类似于以下内容:

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {

  if(indexPath.row==0){
     let cell = tableView.dequeueReusableCell(withIdentifier: "CellWithButton", for: indexPath) as! CellWithButton
  }
  else{
      let cell = tableView.dequeueReusableCell(withIdentifier: "OtherCells", for: indexPath) as! OtherCells
      //here add data for cells from your array
   }  
 return cell
}

最简单的方法是转到UITableView->将UIView拖到常规单元格上方作为标题视图,在其上添加按钮并在ViewController中执行操作,它将始终位于顶部,无需编写任何代码来处理此问题。您不应创建单元格,而应在表视图的标题中添加按钮。添加视图是最好的方法!谢谢@iphone,我不知道为什么我不这么想。再次感谢你!
var dataArray = ["A","B","C"]

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.dataArray.count+1
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    if indexPath.row == 0
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "CreateNewGroupCell") as! CreateNewGroupCell
        return cell
    }
    else
    {
       // Get the data from Array
          let data = self.dataArray[indexPath.row-1]

       // Logic to show other cells
          let cell = tableView.dequeueReusableCell(withIdentifier: "OtherCell") as! OtherCell
          return cell

       // ....
    }

}