简体   繁体   English

Swift:创建静态自定义单元格而不使用dequeueReusableCellWithIdentifier

[英]Swift: Create static custom cell without dequeueReusableCellWithIdentifier

Good morning all, i need to instantiate my custom cell named "CustomCell" in my custom tableViewController without dequeueReusableCellWithIdentifier because this function, due to some interaction that i think that is not necessary to describe for now, replace incorrectly my cells while i'm scrolling (IE the last cell swap with the first and so on). 早上好,我需要在不使用dequeueReusableCellWithIdentifier的情况下在我的自定义tableViewController中实例化名为“ CustomCell”的自定义单元格,因为该功能由于某些交互作用(我认为目前无需描述)在滚动时错误地替换了我的单元格(即,最后一个单元格与第一个单元格交换,依此类推)。

So my code is something like: 所以我的代码是这样的:

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
}

So is this version (with no dequeueReusableCellWithIdentifier) i've no more problems with cell's positioning but i can't click/tap or simply "use" my custom item into cell. 所以这个版本(没有dequeueReusableCellWithIdentifier)是我在单元格的位置上没有更多的问题,但是我不能单击/点击或简单地将我的自定义项“使用”到单元格中。

For example i've a DatePicker like this: 例如,我有一个像这样的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)

and i can't even change the date, i can't tap or generally i can't interact with it. 而且我什至无法更改日期,我无法轻按,或者通常我无法与之互动。 It seems like "userInteractionEnabled is false" but it isn't. 似乎“ userInteractionEnabled为false”,但事实并非如此。

Thank you all in advance, Best regards Marco. 预先谢谢大家,马可先生。

There is a reason that every UITableView example uses dequeueReusableCellWithIdentifier. 每个UITableView示例都使用dequeueReusableCellWithIdentifier是有原因的。 It's how a table view was meant to be used. 这就是使用表视图的方式。

It seems the issue you are actually trying to solve is "the last cell swap with the first and so on." 看来您实际上要解决的问题是“最后一个单元交换与第一个单元交换,依此类推”。 Perhaps that should be your question instead. 也许那应该是您的问题。

In your cell configuration (after dequeue...), reset all of your cells data. 在单元配置中(出队后...),重置所有单元数据。 Can you explain further what is the problem when using dequeue? 您能否进一步说明使用出队的问题是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift中没有dequeueReusableCellWithIdentifier的自定义表单元格 - Custom table cell without dequeueReusableCellWithIdentifier in Swift 自定义UITableViewCell没有dequeueReusableCellWithIdentifier - Custom UITableViewCell without dequeueReusableCellWithIdentifier dequeueReusableCellWithIdentifier引起的崩溃:用于自定义单元格 - Crash caused by dequeueReusableCellWithIdentifier: for custom cell XCode 6问题-dequeueReusableCellWithIdentifier不返回自定义单元格高度 - XCode 6 issue - dequeueReusableCellWithIdentifier not returning custom cell height 从笔尖初始化自定义UITableViewCell而不使用dequeueReusableCellWithIdentifier - Init custom UITableViewCell from nib without dequeueReusableCellWithIdentifier iPhone问题在带有文本字段删除值的自定义单元格中出现dequeueReusableCellWithIdentifier - iPhone Issue with dequeueReusableCellWithIdentifier in custom cell with textfield delete value 使用dequeueReusableCellWithIdentifier方法时如何初始化自定义单元格? - How to init a custom cell when using dequeueReusableCellWithIdentifier method? Swift中的自定义表格视图单元格,没有Storyboard - Custom table view cell in Swift, without Storyboard Swift 在 UIAlertviewcontroller 中使用自定义单元格创建 tableview - Swift create tableview with custom cell within UIAlertviewcontroller 使用Swift 3为iOS应用创建自定义单元格 - Create a custom cell for iOS app using swift 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM