2015-06-23 92 views
1

我想使用索引爲path.row的數組來設置View Controller文件中的詳細標籤的值。註冊一個筆尖

在以前的文章: [鏈接] [1]

有人幫忙,建議我用

var nib = UINib(nibName: "YourCellSubclass", bundle: nil) 
tableView.registerNib(nib, forCellReuseIdentifier: "cell") 

不過我是新來使用這個和整個錯誤傳來:

Cannot invoke registerNib with an argument list of type 'UINib, forCellReuseIdentifier: 'String' 

回答

0

我最好的猜測是,而不是這個:

var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell 

應該是:

var cell: YourSubClass = self.tableView.dequeueReusableCellWithIdentifier("cell") as YourSubClass 

這將編譯在Xcode 7:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let aCell = table.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 

    if let myCell = aCell as? MyCellSubclass { 

     return myCell 
    } 

    return aCell 
} 
+0

這只是:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! MyCellSubclass return cell } 

如果您有多個種類的細胞,你可以去返回錯誤'Undeclared type'我的子類' – GJZ

+0

@GJZ檢查編輯。 – Peres

+0

@RuiAAPerez這似乎是功能,但然後我收到錯誤:無法調用帶標識符的參數列表類型爲字符串 – GJZ