带有CheckMarks的UITableView单元格 [英] UITableView Cell with CheckMarks

查看:77
本文介绍了带有CheckMarks的UITableView单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone项目,该项目的UITableView是从Core Data填充的.

选择一个单元格后,会将用户定向到一个新的视图控制器(请参见下面的代码行),该控制器显示有关该单元格条目的其他信息(来自核心数据)

[self presentModalViewController:noteViewController animated:YES]

我想做的是能够在每个单元格的每一侧设置某种检查标记,以表示任务是否已完成或未完成.

我读到我可以使用:

UITableViewCellAccessoryCheckmark

但是我不确定如何实现当前的

didSelectRowAtIndexPath:

用于显示模式视图控制器.

所以从本质上讲,我想知道是否有一种方法可以独立地将单元格的附件状态从选中标记更改为无(反之亦然),从某种意义上说,如果实际选中标记是触摸的,那么它将显示它. .如果再次触摸它,它将隐藏它.

任何帮助将不胜感激!

解决方案

您将需要从Cell演示文稿的外部跟踪选定的行.这意味着,您的模型(首先用于构建单元的模型)将需要跟踪某种布尔值.设置好后,将accessoryType设置为正确的类型.

if ([[data objectAtIndex:indexPath.row] isSelected]) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}

这是您的一些逻辑:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

I have got an iphone project that has a UITableView which is populated from Core Data..

When a cell is selected, the user is directed to a new view controller (see code line below) which shows additional information about that cell entry (from core data)

[self presentModalViewController:noteViewController animated:YES]

What i want to do is to be able to set some sort of checkmark on either side of each cell to represent whether the task is complete of incomplete..

I have read that i could do this using:

UITableViewCellAccessoryCheckmark

but i am not sure how to implement is as currently

didSelectRowAtIndexPath:

is being used to present the modal view controller..

So essentially i want to know if there is a method for changing the state of a cell's accessory from checkmark to nothing (and vice versa) independently.. in the sense that if the actual checkmark is touch.. it shows it.. and if it is touched again, it hides it..

Any help would be greatly appreciated!

解决方案

You will need to track selected rows externally from Cell presentation. This means, your model (that you used to build the cells in the first place) will need to track some sort of boolean. Once you have that you set accessoryType to the proper type.

i.e.

if ([[data objectAtIndex:indexPath.row] isSelected]) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}

This would be some of the logic in your:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

这篇关于带有CheckMarks的UITableView单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆