【发布时间】:2014-10-27 19:20:31
【问题描述】:
我有一个 UITableview,它列出了用户可以选择用来过滤另一个列表的选项。当单击此表格视图中的项目时,会出现一个复选标记,如果再次单击它,复选标记就会消失。允许用户单击多个 tableview 单元格以同时在许多单元格上显示复选标记。表格视图也分为多个部分。
这在 iOS 8 上一切正常,但是当我在 iOS 7 上运行它时,当我单击单元格时,复选标记不会出现。如果我转到另一个视图然后返回到 tableview 复选标记就在那里。我在stackoverflow上搜索了其他帖子,这些帖子建议我应该尝试将单元格的色调设置为黑色,我尝试过但不起作用。
我还用带有复选标记图像的自定义单元格替换了复选标记,我将其取消隐藏和隐藏。当我单击它们时,这里会显示复选标记,但是当我再次单击它们时,它不会消失。为了清楚起见,我将附上下面的代码。
@property NSMutableArray *favorite;
@property NSMutableArray *favoriteCheckmark;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FilterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"filtercell" forIndexPath:indexPath];
switch (indexPath.section) {
case 0:
cell.textLabel.text = [favorite objectAtIndex:indexPath.row];
if ([favoriteCheckmark containsObject:indexPath]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
}
break;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
FilterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"filtercell" forIndexPath:indexPath];
switch (indexPath.section) {
case 0:
cell.textLabel.text = [favorite objectAtIndex:indexPath.row];
if ([favoriteCheckmark containsObject:indexPath]){
[favoriteCheckmark removeObject:indexPath];
}else{
[favoriteCheckmark addObject:indexPath];
}
break;
}
}
【问题讨论】:
标签: objective-c xcode uitableview ios7