在我的 UItableview 中,我只想让前四行默认勾选?我怎样才能做到这一点?这是我的代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
[am.genar addObject:[ar objectAtIndex:indexPath.row]];
NSLog(@"array content%@",[ar objectAtIndex:indexPath.row]);
if (thisCell.accessoryType == UITableViewCellAccessoryNone)
{
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellAccessoryNone;
}
细胞战指数路径法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.textLabel.text = [ar objectAtIndex:indexPath.row]; // Configure the cell...
if(indexPath.row<4)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
return cell;
}
请帮我解决?