gpt4 book ai didi

ios - 重用单元格时,如何将 UISegmentedControl 的选定段保留在 UITableView 中?

转载 作者:行者123 更新时间:2023-12-01 19:02:14 25 4
gpt4 key购买 nike

我的主要问题是当 UISegmentedControl 所在的单元格被重用时,保持它的选定值。
当我滚动时,重用的单元格对于分段控件仍然具有相同的值。

- (UITableViewCell *)tableView:(UITableView *)thisTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"yesNoCell";
testCell = [thisTableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...
testCell.mainText.text = [ questionArray objectAtIndex:indexPath.row];
[testCell.mainControl setFrame:CGRectMake(690, 22, 334, 40)];

return testCell;
}

编辑澄清:
我想保留每一行的选择。例如,我可能有 10 行可见的行和总共 30 行。当我在第 3 行中选择一个段时,“3”消失时显示的行具有相同的选定段。我想确保具有选定段的唯一行是用户实际更改的行。

最佳答案

您的 型号对于每一行都应该有一个属性来保留选定的段,我们称之为 selectedSegment .当用户点击一个段时,您会影响 selectedSegment 的值。表示受影响行的对象实例的属性。

然后在你的cellForRowAtIndexPath:方法,您使用 selectedSegment 的值更新 UISegmentedControl 的选定索引属性(property)。

关于ios - 重用单元格时,如何将 UISegmentedControl 的选定段保留在 UITableView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22058512/

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