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.isBottom = false if(indexPath.row == myArray.count-1){ cell.isBottom = true } return cell}
这是我的RunningtableVIEwCell类:( Cell的GUI在故事板内部制作)
class RunningtableVIEwCell: UItableVIEwCell { //@IBOutlet ... @IBOutlet weak var mybutton: Somebutton! var istop: Bool? var isBottom: Bool? overrIDe func awakeFromNib() { super.awakeFromNib() print("result: \(self.istop) \(self.isBottom)") mybutton.istop = self.istop mybutton.isBottom = self.isBottom }}
它返回结果:nil nil
结果的用法是:( Somebutton是RunningtableVIEwCell内的子视图)
class Somebutton: UIbutton { var istop = false var isBottom = false overrIDe func drawRect(rect: CGRect) { if(istop){ // DO SOMETHING... } if(isBottom){ // DO SOMETHING... } }}
那么如何将数据传递给RunningtableVIEwCell呢?
解决方法 您需要覆盖单元格中的prepareForReuse.并从tableVIEw:indexPath:中删除它.因此,当您滚动时,将重复使用单元格,但isBotton和istop vars将被重置.overrIDe func prepareForReuse() { self.isBottom = false self.istop = false}@H_301_2@ 总结
以上是内存溢出为你收集整理的ios – 从UIViewController将变量传递给自定义UITableViewCell全部内容,希望文章能够帮你解决ios – 从UIViewController将变量传递给自定义UITableViewCell所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)