2016-01-12 58 views
2

我遇到了一個奇怪的錯誤。這行代碼正常工作:當使隊列出隊時對成員'tableView'的歧義引用

let cell = self.tableView.dequeueReusableCellWithIdentifier("FeedCell", forIndexPath: indexPath) as UITableViewCell! 

然而,當我轉換爲FeedCell!(的UITableViewCell一個子類):

let cell = self.tableView.dequeueReusableCellWithIdentifier("FeedCell", forIndexPath: indexPath) as FeedCell! 

Xcode中引發錯誤:Ambiguous reference to member 'tableView'

我不知道怎麼樣它可能是模棱兩可的,更不用說由不同的角色觸發了!

+0

請檢查http://stackoverflow.com/a/33724276/5362916 –

+0

我檢查了這一點 - 但我使用的是UITableViewController而不是UIViewController的子類。創建一個名爲'tableView'的IBOutlet只是衝突。 此外,爲什麼會由我投射到不同的細胞子類觸發? – jonlambert

+1

您可能從已將'tableView'作爲參數的'UITableViewControllerDataSource'方法調用此方法。嘗試將'self.tableView'更改爲'tableView'。 – redent84

回答

4

嘗試改變線

let cell = tableView.dequeueReusableCellWithIdentifier("FeedCell", forIndexPath: indexPath) as! FeedCell 

只需刪除!從FeedCell!,並把它放在as!並檢查是否有任何區別。

除了在他的評論中提到的@ redent84,你應該使用tableView而不是self.tableView

+0

這實際上工作!爲什麼Xcode會拋出其他錯誤,然後呢?! – jonlambert

+0

我不知道爲什麼這個錯誤消息。我剛剛發現你寫作的方式不對,並建議改變它,它可能會解決奇怪的錯誤。即使它沒有解決它,它仍然值得改變。 – Ismail

相關問題