iphone - 常数复选标记

标签 iphone ios uitableview

在我的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;
}

请帮我解决?

最佳答案

- (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;
}

让我知道我是否无法正确理解您的查询。我将相应地进行修改。快乐的编码:)

关于iphone - 常数复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12470878/

相关文章:

ios - UIView-Encapsulated-Layout-Height : Invalid constraints in tableHeaderView

iphone - 重写内部 UIViewController 方法,因为内部方法给我带来了错误

iphone - 更改 Tab Bar 应用程序中 UITableViewController 的样式

iphone - 如何从照片中获取exif?

ios - Xcode "Undefined symbols for architecture i386"错误,代码没有任何变化,突然

iphone - 检测 iPhone MapView 上开始的捏合手势

ios - UITableViewCell 中 UILabel 的布局警告不明确

ios - 如何设置tableview单元格的文本和详细文本?

iphone .png 图像未显示在设备中

ios - Grand Central Dispatch 和单元测试