2015-11-24 133 views
0

我無法將我的UITableViewCell強制轉換爲我的自定義類。我有一個擴展UITableViewCell的BaseCell類,然後是一個擴展BaseCell的ProfilePictureCell類。我想在的cellForRowAtIndexPath投,像這樣:無法強制轉換UITableViewCells

if row == kProfilePictureRow { 
     cell = tableView.dequeueReusableCellWithIdentifier(kProfilePicIdentifier) as? ProfilePictureTableViewCell 
    } 

但是,這永遠只能使細胞一個UITableViewCell類。我試過註冊班級和筆尖,都無濟於事。我在故事板中設置了標識符,我不確定我錯過了什麼?

爲什麼我不能像鑄造到不同的tableView單元格子類那樣簡單?

回答

0

我不知道你有什麼聲明,但這裏是Custom UITableViewCell的工作示例。

首先,把變量作爲您的自定義UITableViewCell

var cell: CustomTableViewCell? 

,然後你可以使用雙端隊列的標識如下:

cell = tableView.dequeueReusableCellWithIdentifier("your_identifier", forIndexPath: indexPath) as? CustomTableViewCell 

希望,它幫助!

-1

也許問題是因爲使用的是as?嘗試使用as!as?

也細胞不應該Optional因爲func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> UITableViewCell必須返回UITableView

相關問題