ios - 静态 UITableView 单元格内的动态 UITableView 数据源

标签 ios swift uitableview

可能有更好的方法来做到这一点,但我整天都在谷歌搜索,找不到解决我的具体问题的办法:

我有一个静态 TableView,它显示大量信息并包含一个文本输入部分,用于将值添加到嵌套在父静态 TableView 的一个单元格中的动态 TableView。

为此,我在 UITableViewController 中有一个 UITableViewDataSource 和 UITableViewDelegate 的子类,它们将控制嵌套 TableView 中显示的内容。我有一个嵌套表的导出:

@IBOutlet weak var validatedCardsTable: UITableView!

在我的 viewDidLoad 中有:

let dataSource = ValidatedCardsDataSource(tableView: self.validatedCardsTable)
self.validatedCardsTable.dataSource = dataSource
self.validatedCardsTable.delegate = dataSource

我的子类是这样的:

class ValidatedCardsDataSource :NSObject, UITableViewDataSource, UITableViewDelegate {

    var tableView:UITableView

    init(tableView : UITableView) {
        self.tableView = tableView
        super.init()
    }

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 100
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return 1
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell
        cell.textLabel!.text = "Title of Row: #\(indexPath.row)"
        return cell
    }
}

当我运行这段代码时,嵌套的 TableView 会加载我在 cellForRowAtIndexPath 中设置的适当的“行标题”文本(尽管 tableview 没有调整大小,但我敢肯定这完全是另一个问题).但是,当我在任何地方按下 TableView 时,我在 Storyboard 中的单元格原型(prototype)中指定的标签“A Label”也会显示在单元格上,然后当我松开按键时,所有格式都会消失并且单元格会恢复原状到默认状态。我假设我没有完全将某些东西卡在某个地方,但是您可以提供任何帮助来追踪我做错了什么,或者建议更好的方法来处理这个问题,我们将不胜感激!截图如下:

原型(prototype)细胞:

Prototype Cell

加载时显示的内容:

loaded

触地时显示的内容:

loaded

触摸时显示的内容:

loaded

最佳答案

覆盖你的单元格方法“touchesBegan:withEvent:/touchesEnded:withEvent:/touchesCancelled:withEvent:” 当单元格被向下/向上/向上触摸时,改变 UI 样式。

关于ios - 静态 UITableView 单元格内的动态 UITableView 数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37799070/

相关文章:

ios - 如何理解dart异步操作?

ios - 计算在collectionView单元格中使用的NSString高度

ios - 重新加载数据后,UITableView 中的 UIView 动画不起作用

ios - UITableView 单元格有时无法更新图像,但滚动后显示正常

ios - 如何解决线程1 :EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP, subcode=0x0)

objective-c - didReceiveRemoteNotification 没有被调用

ios - VNCoreMLRequest始终返回相同的结果

json - 使用 Swift 4 Decodable 解析 JSON

ios - Swift:如何通过按导航栏按钮访问选项卡栏项目

ios - 如何在 iphone 中获取单元值?