代码之家  ›  专栏  ›  技术社区  ›  Jaydeep Vyas

UITableView单元重用标识符

  •  0
  • Jaydeep Vyas  · 技术社区  · 9 年前

    我为不同的单元标识符创建了一个结构:

    enum CustomCellIdentifiers
    {
        static let cellForCountry = "cellForCountry"
        static let cellForCity = "cellForCity"
        static let cellForStoreType = "cellForStoreType"
    }
    

    view.tableForItems.register(UINib.init(nibName: cellIdentifier, bundle: nil), forCellReuseIdentifier:cellIdentifier)
    

    但当我注册手机时,我错误地发现 reuseIdentifier 为零:

     class CustomTableCell: UITableViewCell
        {
        override func awakeFromNib()
            {
                super.awakeFromNib()
                // Initialization code
                switch self.reuseIdentifier ?? "cellForCountry" //It only work with country cell
    {
                case CustomCellIdentifiers.cellForCountry:
                     print("cellForCountry") break;
                case CustomCellIdentifiers.cellForCity:
                     print("cellForCity")                break;
                case CustomCellIdentifiers.cellForStoreType:
                                    print("cellForStoreType")
                    break;
                default: break
    
                }
            }
        }
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   Jaydeep Vyas    9 年前

    设置 reUseIdentifier 在 xib 文件也是。 使用UITableviewcell类来创建xib,而不是UIView。。

    请参见下图

    enter image description here