gpt4 book ai didi

ios - 什么叫setSelected :NO method automatically

转载 作者:技术小花猫 更新时间:2023-10-29 10:51:42 26 4
gpt4 key购买 nike

我在使用 UITableView 和 UITableViewCell 时遇到了这个奇怪的问题。每当 -tableView:cellForRowAtIndexPath:被称为 setSelected:NO 之后被调用。

-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSDictionary *cellData = dataSource[indexPath.row];

NSString *cellId = nil;
//choose cell type
NSInteger type = [[cellData valueForKey:@"type"] integerValue];
switch (type) {
case 0:
//root level
cellId = @"rootHeaderCell";
break;
case 1:
//sub header
cellId = @"subHeaderCell";
break;
case 2:
default:
//value row - radiobutton
cellId = @"radiobuttonCell";
break;
}

CSBaseFilterCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId
forIndexPath:indexPath];

// Configure the cell...
[cell setData:cellData];

return cell;
}

cellData包含有关选择和单元格中的信息:

-(void)setData:(NSDictionary *)data {

NSLog(@"Set Data");
NSLog(@"data has selected=%d", [data hasKey:@"selected"]);
NSLog(@"data.selected=%@", [data valueForKey:@"selected"]);

if ([data hasKey:@"selected"]) {
[self setSelected:[[data valueForKey:@"selected"] boolValue]
animated:NO];

}
}

我设置了选择,但是没有被选中。我在 setData 中放置了痕迹并且值很好,我在 setSelected:animated: 中放置了痕迹并发现进行了 3 次调用:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
NSLog(@"%@ setSelected:selected=%d",self,selected);


self.accessoryType = selected ? UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;
}

这是日志输出中显示的内容:

2014-06-05 21:11:59.679 UITableView Filter Sort[42821:60b] Set Data
2014-06-05 21:11:59.679 UITableView Filter Sort[42821:60b] data has selected=1
2014-06-05 21:11:59.680 UITableView Filter Sort[42821:60b] data.selected=1
2014-06-05 21:11:59.680 UITableView Filter Sort[42821:60b] <CSRadioButtonCell: 0x8c80630; baseClass = UITableViewCell; frame = (0 64; 320 32); autoresize = W; layer = <CALayer: 0x8c76920>> setSelected:selected=1
2014-06-05 21:11:59.686 UITableView Filter Sort[42821:60b] <CSRadioButtonCell: 0x8c80630; baseClass = UITableViewCell; frame = (0 64; 320 32); autoresize = W; layer = <CALayer: 0x8c76920>> setSelected:selected=0
2014-06-05 21:11:59.811 UITableView Filter Sort[42821:60b] <CSRadioButtonCell: 0x8c80630; baseClass = UITableViewCell; frame = (0 64; 320 32); autoresize = W; layer = <CALayer: 0x8c76920>> setSelected:selected=0

表放在ViewController ,它不是 UITableViewController。

更新我已经把 setData: call in willDisplayCell:forRowAtIndexPath:并删除了对 setSelected 的 super 定义的调用,这解决了问题。它仍然在日志中显示在 cellForRowAtIndexPath 中的 setData 之间调用 setSelected 时没有参数和 willDisplayCell:forRowAtIndexPath:但至少 willDisplay 是最后一个:)

我也尝试过使用自己的“选择”属性成功 checkedsetData: 中设置在didSelectRowAtIndexPath: .

最佳答案

中执行 setSelected - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

关于ios - 什么叫setSelected :NO method automatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24069410/

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