gpt4 book ai didi

ios - 从 UITableViewCell 获取数据

转载 作者:行者123 更新时间:2023-11-28 23:57:47 25 4
gpt4 key购买 nike

我想从 UITableViewCell 获取数据。这是我的代码。

[selection CreateTableview:colorList withSender:sender  withTitle:@"Please Select" setCompletionBlock:^(int tag){

NSLog(@"Tag--->%d",tag);
NSLog(@"Selected Row %ld",(long)indexPath.row);
updated_lenses = tag;

[self.tableview reloadData];

}];

我在这里选择了索引,但我想获取该单元格内的值,如何获取它。?注意:我没有使用 DidSelectRowAtIndexPath 方法。

最佳答案

就我而言,有两种方法可以从单元格中获取数据。

方法一
将必要的数据放入 UITableViewCell 的子类中。

class MyTableViewCell: UITableViewCell {
var property1: String = ""
var property2: Int = 2
}

方法 2。
将数据放在structclass中,让它成为table view的数据源。

struct CellData {
var property1: String = ""
var property2: Int = 0
}
var cellDataList: [CellData] = [] ///< This decide how many cell for table view.

// For UITableView DataSource & Delegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellDataList.count
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let data = cellDataList[indexPath.row]
// .....
}

关于ios - 从 UITableViewCell 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50636957/

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