我正在做關於聯繫人列表數據的項目,這樣我將獲取數據並將其放置在表視圖中,我需要選擇特定的聯繫人在一行中,選中後應用複選標記,並在取消選擇聯繫人後刪除複選標記。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