在我的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;
}
cellrowarindexpath方法
- (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;
}
请帮我解决一下?
答案 0 :(得分:4)
- (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] autorelease];
}
if(indexPath.row < 4) //considering that you need FIRST four rows to be checkmarked by default
cell.accessoryType = UITableViewCellAccessoryCheckmark;
return cell;
}
如果我没有正确理解你的查询,请告诉我。我会做出相应的修改。快乐的编码:)