ios - 注册自定义 TableCell xib 给我一个错误

标签 ios swift uitableview

我得到错误:

Argument labels '(_:, forCellWithReuseIdentifier:)' do not match any available overloads

我不确定为什么,因为这非常适合我的 CollectionView 单元格:

class DashboardVC: UIViewController,  UICollectionViewDelegate, UICollectionViewDataSource, UITableViewDelegate, UITableViewDataSource {

let ownedItemArray = ["Owned Item 1","Owned Item 2","Owned Item 3"]
let shopItemArray = ["Shop Item 1","Shop Item 2","Shop Item 3", "Shop Item 4","Shop Item 5","Shop Item 6"]
let freeItemArray = ["Free Item 1","Free Item 2","Free Item 3"]


@IBOutlet weak var ownedItemsCollection: UICollectionView!
@IBOutlet weak var shopItemsCollection: UICollectionView!
@IBOutlet weak var freeItemsTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    ownedItemsCollection.delegate = self
    ownedItemsCollection.dataSource = self
    shopItemsCollection.delegate = self
    shopItemsCollection.dataSource = self
    freeItemsTableView.delegate = self
    freeItemsTableView.dataSource = self

    ownedItemsCollection.register(UINib(nibName:"OwnedCell", bundle: nil), forCellWithReuseIdentifier: "owned_item")
    shopItemsCollection.register(UINib(nibName: "ShopListCell", bundle: nil), forCellWithReuseIdentifier: "shoplist_item")
    freeItemsTableView.register(UINib(nibName: "FreeItem", bundle: nil), forCellWithReuseIdentifier: "free_items")

}

最佳答案

对于 UITableView 使用
freeItemsTableView.register(UINib(nibName: cellNibName, bundle: nil), forCellReuseIdentifier: cellReuseId).
注意第二个参数名称,不是forCellWithReuseIdentifier而是forCellReuseIdentifier

关于ios - 注册自定义 TableCell xib 给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49023987/

相关文章:

swift - 协议(protocol)继承 Swift

ios - 如何从 UICollectionView 中获取多个选中的 CollectionViewCell?

ios - TableView : method editingStyleForRowAtIndexPath

ios - UITableView vs UICollectionView vs UIScrollView?

ios - 无法在 iOS 中连接 SQLite 数据库

iphone - initWithNibName 不工作

ios - Swift - UIAlertController 后操作

swift - 在 Swift 中获取 UIAlertAction 的处理程序

iphone - 无法解析 XML iPhone

ios - 使用视觉格式语言使 UIButton 之间的间距相等