如果我取消如何在Swift中使用dequeueReusableCellWithIdentifier?
tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?)
我上寫着UITableView? does not have a member named 'dequeueReusableCellWithIdentifier'
如果我拆禮物的tableview那麼錯誤消失行
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
得到一個錯誤,但在Objective-C,我們通常會檢查單元格是否存在,如果不存在,我們會創建一個新單元格。在Swift中,由於提供的樣板文件使用關鍵字let
,並打開一個可選項,所以如果它爲零,我們不能重新分配它。
什麼是在Swift中使用dequeueReusableCellWithIdentifier的正確方法?
。不用這種方法。 docs:「UITableViewCell對象與關聯的重用標識符。該方法總是返回一個有效的單元格」 –
困惑的我也因爲我記得ObjC日子裏你檢查爲零的情況下,如果沒有細胞重用,並且如果零創建一個新的使用'reuseIdentifier'的單元格。我再次閱讀當前的Apple文檔,它說:「如果有現成的單元格可用,或者使用之前註冊過的類或nib文件創建一個新的單元格,則此方法會將其取出。」所以,現在這個功能對我們來說都很好,這很好。雖然看到這個討論,但有2個出列調用 - 一個返回可選,另一個不可以:[link](https://www.natashatherobot.com/ios-using-the-wrong-dequeuereusablecellwithidentifier/) –