gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 00:54:07 25 4
gpt4 key购买 nike

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

我有一个静态 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com