我正在做关于联系人列表数据的项目,这样我将获取数据并将其放置在表视图中,我需要选择特定的联系人在一行中,选中后应用复选标记,并在取消选择联系人后删除复选标记。iOS:添加复选标记来选择tableview中的特定行
I have searched different sites but cannot able to find the exact answer please help.
我正在做关于联系人列表数据的项目,这样我将获取数据并将其放置在表视图中,我需要选择特定的联系人在一行中,选中后应用复选标记,并在取消选择联系人后删除复选标记。iOS:添加复选标记来选择tableview中的特定行
I have searched different sites but cannot able to find the exact answer please help.
试试这个,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
击败我!大声笑 – rebello95 2014-10-06 06:31:54
我需要在桌面左侧的复选标记,当我选择它应该是选择和选择同一行后,它应该删除所选行上的将军 – 2014-10-06 06:38:55
你需要定制它。你可以给它添加一个'UIButton'和动作。 – iDeveloper 2014-10-06 06:40:12
有一个很简单的解决方案。 UITableView
自己管理行的选择。它也支持多选。只需指定您的细胞在选定状态下的外观。
创建UITableViewCell
子类作为以下代码并在您的UITableView
中使用它。无需重写didSelectRowAtIndexPath等。
@interface CheckCell : UITableViewCell
@end
@implementation CheckCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if (self.isSelected)
self.accessoryType = UITableViewCellAccessoryCheckmark;
else
self.accessoryType = UITableViewCellAccessoryNone;
}
@end
请引用此答案。 http://stackoverflow.com/a/3667155/3615320 – Chan 2014-10-06 06:51:08
试试这个 http://stackoverflow.com/questions/5958740/how-to-place-the-checkbox-in-tableview-细胞 – user3540599 2014-10-06 06:57:47