简体   繁体   中英

UITableViewCell disclosure indicator disappears on scrolling

I have a custom tableViewCell with some subviews defined in a prototype cell in a storyboard. In the storyboard I set the Accessory to Disclosure Indicator, but when scrolling (when cells are reused) the indicator disappears.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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