gpt4 book ai didi

iphone - 常数复选标记

转载 作者:行者123 更新时间:2023-12-01 18:27:07 25 4
gpt4 key购买 nike

在我的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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com