Pass variable to custom UITableViewCell from UIViewController

前端 未结 4 740
死守一世寂寞
死守一世寂寞 2021-01-20 20:59

Here is how I use my custom UITableViewCell RunningTableViewCell inside UIViewController:

func tableView(tableView: UITableView, ce         


        
4条回答
  •  鱼传尺愫
    2021-01-20 21:45

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as! RunningTableViewCell
    
        //.......
    
        cell.isTop = false
        if(indexPath.row == 0){
            cell.isTop = true
            cell.tag=100
        }
    
        cell.isBottom = false
        if(indexPath.row == myArray.count-1){
            cell.isBottom = true
            cell.tag=200
        }
    
        return cell
    }
    

    and also get this like ...

    class RunningTableViewCell: UITableViewCell {
    
            //@IBOutlet ...
    
            var isTop: Bool?
            var isBottom: Bool?
    
            override func awakeFromNib() {
                super.awakeFromNib()
                if (self.tag==100)
                {
                    isTop=true
                }
                else if (self.tag==200) {
                    isBottom=true
                }
                else{
                    isTop=false
                    isBottom=false
                }
    
                print("result: \(self.isTop) \(self.isBottom)")
            }
        }
    

    And also do using singleton methods...

提交回复
热议问题