UITableViewCell披露指示符在滚动时消失

时间:2014-03-24 13:33:27

标签: ios objective-c uitableview

我有一个自定义tableViewCell,其中一些子视图在故事板中的原型单元格中定义。在故事板中,我将附件设置为Disclosure Indicator,但在滚动时(当重复使用单元格时)指示符会消失。

我尝试在代码中设置它:

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

它没有用。但我找到了一个有效的解决方案,一个非常奇怪的解决方案:

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

我不知道为什么这可以解决任何问题,但它对我有用。任何人都可以告诉我为什么或者是否有其他问题/修复?

更新:

我如何获得可重复使用的单元格:

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

我也尝试过:

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

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

}

1 个答案:

答案 0 :(得分:0)

尝试使用此变体:

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

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