简体   繁体   English

UITableView某些单元格不可见

[英]UITableView some cells not visible

I have run into a strange problem with UITableViews. 我遇到了UITableViews的一个奇怪问题。 Some of the cells in my table are positioned to the far right right of the screen, making it unreadable save for the first few characters. 我表格中的某些单元格位于屏幕的最右端,除了前几个字符外,它不可读。 When I scroll through the table the affected cells change. 当我滚动浏览表格时,受影响的单元格会发生变化。 I have added a couple of screenshots to help better understand what I'm dealing with. 我添加了一些屏幕截图,以帮助更好地了解我正在处理的内容。

Some views are invisible 一些视图不可见

Different views are invisible 不同的观点是看不见的

I have used the following code to populate the table: 我使用以下代码填充表:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"NewCell";
    NewProductCell *cell = [tableView
                           dequeueReusableCellWithIdentifier:CellIdentifier
                        forIndexPath:indexPath];

    long row = [indexPath row];

    cell.medicineLabel.text = [_medicineArray objectAtIndex:row];
    if([[_medicineArray objectAtIndex:row]  isEqual: @"Alfabetisch"]||    [[_medicineArray objectAtIndex:row]  isEqual: @"Eerder besteld"]){
        [cell setUserInteractionEnabled:NO];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    return cell;
}  

_medicinceArray is a list of strings fetched from a webserver, I have verified this is not the source of the problem. _medicinceArray是从Web服务器获取的字符串的列表,我已经证实这不是问题的根源。

Thanks in advance. 提前致谢。

I guess there's something wrong with your cell's state. 我想您的单元格状态有问题。 Especially when the cells are not working RANDOMLY. 特别是当单元不能随机工作时。

You should pay attention that the cells are reusable. 您应该注意这些单元是可重用的。 From your code, I think you want only the cells with value @"Alfabetisch" or @"Eerder besteld" are disabled, others are interactive. 从您的代码中,我认为您只希望禁用值为@“ Alfabetisch”或@“ Eerder besteld”的单元格,而其他单元则是交互式的。

But what really happens? 但是到底发生了什么?

If you scroll up and down, the disabled cells are moving outside of the view, eventually some of them are reused to act like another cell to show the data that should be enabled, but since there are no codes to enable them, it will keep disabled. 如果向上或向下滚动,则禁用的单元格将移动到视图外部,最终它们中的一些单元格将像另一个单元格一样被重用,以显示应启用的数据,但是由于没有启用它们的代码,它将保持禁用的。 As a result, if you try more, all cells are disabled in the end. 结果,如果您尝试更多,最后所有单元将被禁用。

So for your question, it may also be the reason for the strange behavior of your invisible labels. 因此,对于您的问题,这也可能是看不见标签行为异常的原因。

You should check the codes outside of the method(any code to modify the cells or the labels), or the label's auto-layout in the cell in your storyboard. 您应该检查方法之外的代码(用于修改单元格或标签的任何代码),或故事板中单元格中标签的自动布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM