简体   繁体   English

UITableViewCell 显示指示器在滚动时消失

[英]UITableViewCell disclosure indicator disappears on scrolling

I have a custom tableViewCell with some subviews defined in a prototype cell in a storyboard.我有一个自定义 tableViewCell,其中一些子视图定义在故事板的原型单元格中。 In the storyboard I set the Accessory to Disclosure Indicator, but when scrolling (when cells are reused) the indicator disappears.在故事板中,我将 Accessory 设置为 Disclosure Indicator,但是当滚动时(当单元格被重用时),指示器消失了。

I tried to set it in code:我试图在代码中设置它:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ...
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

It did not work as well.它也没有奏效。 But I found a working solution, a very weird solution:但我找到了一个有效的解决方案,一个非常奇怪的解决方案:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ...
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

I don't know why this can fix anything, but it works for me.我不知道为什么这可以解决任何问题,但它对我有用。 Can anyone tell me why or if there is an other problem/fix?谁能告诉我为什么或者是否有其他问题/修复?

UPDATE:更新:

How i get the reusable cell:我如何获得可重复使用的单元格:

ActivityWeekCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

I also tried:我也试过:

ActivityWeekCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

if (cell == nil) {
    cell = [[ActivityWeekCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

}

Try to use this variant:尝试使用此变体:

ActivityWeekCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

if (cell == nil) {
    cell = [[ActivityWeekCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

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

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