【发布时间】:2014-04-28 07:31:11
【问题描述】:
我有一个在 XCODE 中这样创建的 tableview(无代码)。
我试图在按下任一行时在右侧打勾,我使用的是 IOS7。
这引起了一些噩梦。这是我正在实现的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = [UITableViewCell new];
cell.tintColor = [UIColor blackColor];
if(cell.selected){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
}
【问题讨论】:
-
You appear to be creating a new cell when a row is selected.你觉得这样对吗?
-
您必须将选定的单元格状态存储在本地,然后在 cellForRowAtIndexPath 中检查它的状态,它之前是否被选中。
标签: ios objective-c uitableview