Show two different custom cells in same uitableview - swift firebase

前端 未结 6 1550
心在旅途
心在旅途 2021-02-06 20:15

I am currently having a problem with displaying two different types of custom cells on the same uitableview.

What I have managed so far, is receiving the \"updates\" to

6条回答
  •  情话喂你
    2021-02-06 20:24

        override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    
            return 2
        }
    
        override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
            switch section {
            case 0:
                return updates.count
            case 1:
                return updatesTask.count
            default:
                return 0
            }
        }    
    
        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
            switch indexPath.section {
            case 0:
                let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! updateTableViewCell
                let update = updates[indexPath.row]
    
                cell.nameLabel.text = update.addedByUser
    
                return cell
            case 1:
                let cell = tableView.dequeueReusableCellWithIdentifier("TaskCell", forIndexPath: indexPath) as! tasksTableViewCell
                let updateTask = updatesTask[indexPath.row]
    
                cell.nameLabel.text = updateTask.addedByUser
    
                return cell
            default:
                return UITableViewCell()
            }
        }
    

提交回复
热议问题