[英]Custom table cell without dequeueReusableCellWithIdentifier in Swift
[英]Swift: Create static custom cell without dequeueReusableCellWithIdentifier
早上好,我需要在不使用dequeueReusableCellWithIdentifier的情況下在我的自定義tableViewController中實例化名為“ CustomCell”的自定義單元格,因為該功能由於某些交互作用(我認為目前無需描述)在滾動時錯誤地替換了我的單元格(即,最后一個單元格與第一個單元格交換,依此類推)。
所以我的代碼是這樣的:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> CustomCell {
// NEW VERSION HERE ---------
var cell = CustomCell()
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.userInteractionEnabled = true
cell.clipsToBounds = false
// OLD VERSION HERE ---------
//var cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) as! CustomCell
// Configure my cells....
return cell
}
所以這個版本(沒有dequeueReusableCellWithIdentifier)是我在單元格的位置上沒有更多的問題,但是我不能單擊/點擊或簡單地將我的自定義項“使用”到單元格中。
例如,我有一個像這樣的DatePicker:
var dynamicPicker = UIDatePicker(frame: CGRectMake(0, 0, self.frame.width, 192.0))
dynamicPicker.date = date_
dynamicPicker.addTarget(self, action: "pickerChanged:", forControlEvents: UIControlEvents.ValueChanged)
view.addSubView(dynamicPicker)
而且我什至無法更改日期,我無法輕按,或者通常我無法與之互動。 似乎“ userInteractionEnabled為false”,但事實並非如此。
預先謝謝大家,馬可先生。
每個UITableView示例都使用dequeueReusableCellWithIdentifier是有原因的。 這就是使用表視圖的方式。
看來您實際上要解決的問題是“最后一個單元交換與第一個單元交換,依此類推”。 也許那應該是您的問題。
在單元配置中(出隊后...),重置所有單元數據。 您能否進一步說明使用出隊的問題是什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.