gpt4 book ai didi

iphone - 表格单元格相互渗透

转载 作者:行者123 更新时间:2023-11-29 05:01:12 24 4
gpt4 key购买 nike

我在表格单元格方面遇到了一个以前从未见过的奇怪问题。当我滚动表格时,它们正在互相渗透。例如,现在我在第一部分中有一个单元格显示“设备”,在第二部分中有一堆单元格显示“嗨”,然后在第三部分中有一些空白单元格。当我滚动时,有时“设备”会写在“Hi”之上(因此两个标签都可见,但相互重叠(它们具有清晰的背景色),有时“Hi”会写在第三部分的单元格中。我一直在试图找出问题所在,但似乎没有任何作用。

以下是我的 TableView Controller 的相关部分:

- (id)initWithDeviceCoordinator:(DeviceCoordinator*)dev_con
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
device_coordinator = dev_con;
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (section == 0 || section == 3) return 1;
else if (section == 1) return 8;
else if (section == 2) return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

if (indexPath.section == 0) cell.textLabel.text = [device_coordinator getDeviceName];
else if (indexPath.section == 1)
{
if (indexPath.row == [[device_coordinator getChannelList] count])
{
cell.textLabel.text = @"Add new channel";
return cell;
}
cell.textLabel.text = @"HI";
return cell;
}
return cell;
}

该类中的所有其他函数都是 XCode 默认的。

最佳答案

您应该首先设置cell.textLabel.text = nil,否则当单元格被重用时,您会在错误的位置看到文本(就像您说您在不应该看到的地方看到了“Hi”) t出现)。至于重叠标签,我认为您粘贴的代码不会导致这种情况。您使用自定义单元格吗?

关于iphone - 表格单元格相互渗透,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6900669/

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