Show two different custom cells in same uitableview - swift firebase

前端 未结 6 1541
心在旅途
心在旅途 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:19

    I am not sure what you want to achieve. If you want to display the number of cells updates[] and updatesTask[] have elements you can do it like this

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (updates.count + updatesTask.count)
    }
    

    then you can modify your cellForRowAtIndexPath method like this:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell:updateTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! updateTableViewCell
        let cellTask:tasksTableViewCell = tableView.dequeueReusableCellWithIdentifier("TaskCell", forIndexPath: indexPath) as! tasksTableViewCell
    
    if indexPath.row < updates.count{
     //update 
     let update = updates[indexPath.row]
     cell.nameLabel.text = update.addedByUser
    }else{
        let updateTask = updatesTask[indexPath.row]
        cellTask.nameLabel.text = updateTask.addedByUser 
    }
    
        return cell
    }
    

    with the if condition you can choose from which array you are taking data. But be careful to name an array exactly the same as another constant like you did here

    let updateTask = updatesTask[indexPath.row]
    

提交回复
热议问题