Man*_*nsi 2 iphone cocoa-touch objective-c uikit
我在下面的代码中实现了这个.
UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath];
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell2.accessoryType = UITableViewCellAccessoryNone;
oldIndexPath1 = indexPath;
Run Code Online (Sandbox Code Playgroud)
但是,如果我选择然后取消选中复选标记,则我无法再选中复选标记.
你能帮助我吗?
我认为你混淆了将支票从一个改为另一个的动作以及仅切换一个单元的动作.
假设您只需要一个带有复选标记的单元格,则可以执行以下操作:
+(void)toggleCheckmarkedCell:(UITableViewCell *)cell
{
if (cell.accessoryType == UITableViewCellAccessoryNone)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
// tableView:didSelectRowAtIndexPath:
UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath];
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1];
// Toggle new cell
[MyController toggleCheckmarkedCell:cell];
if (cell != cell2) // only toggle old cell if its a different cell
[MyController toggleCheckmarkedCell:cell2];
oldIndexPath1 = indexPath;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4383 次 |
| 最近记录: |