Ios 使用某些UITableViewCell

Ios 使用某些UITableViewCell,ios,uitableview,Ios,Uitableview,如何选择几个UITableViewCell(作为复选标记,但使用我自己的样式),然后对所选项目执行操作 作为复选标记(或其他),我想使用UIImageView: -(void)tableView:(UITableView*)tableView未选择rowatindexpath:(nsindepath*)indepath { UITableViewCell*thisCell=[tableView cellForRowAtIndexPath:indexPath]; if(thisCell.acces

如何选择几个
UITableViewCell
(作为复选标记,但使用我自己的样式),然后对所选项目执行操作

作为复选标记(或其他),我想使用
UIImageView

-(void)tableView:(UITableView*)tableView未选择rowatindexpath:(nsindepath*)indepath

{

UITableViewCell*thisCell=[tableView cellForRowAtIndexPath:indexPath];
if(thisCell.accessoryType==UITableViewCellAccessoryNone)
{
thisCell.accessoryType=UITableViewCellAccessoryCheckmark;
}
其他的
{
对于要添加到的(int i=0;i),如果要使用自己的复选标记图像,可以设置自定义附件视图,并遵循他指定的相同逻辑

要设置自定义附件视图,请使用

cell.accessoryView = myAccessoryView; //myAccessoryView is a UIImageView holding your custom check mark image

按照下面的步骤做。为此,您必须使用NSMutableArray。我在这里使用了ArrMethodsToBester

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

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    cell.textLabel.textColor=[UIColor darkGrayColor];
    cell.textLabel.font= [UIFont fontWithName:@"Arial Rounded MT Bold" size:15.0];

    Scope_RepairMethod *scpObj=[repairMethodArr objectAtIndex:indexPath.row];
    cell.textLabel.text= scpObj.strRepairMethod;

    if([self.checkedIndexPath isEqual:indexPath])
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   // NSString *selID;

    UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];

    Scope_RepairMethod *scpObj=[repairMethodArr objectAtIndex:indexPath.row];

    if (newCell.accessoryType == UITableViewCellAccessoryNone)
    {
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
        [arrMethodsToBeStored addObject:scpObj.strRepairMethod];
    }
    else
    {
        newCell.accessoryType = UITableViewCellAccessoryNone;
        [arrMethodsToBeStored removeObject:scpObj.strRepairMethod];
    }
    NSLog(@"selected method arr==== %@",arrMethodsToBeStored);


// I want to enable my save button only if one or more values from table are selected

    if(arrMethodsToBeStored.count > 0)
        saveBtn.enabled=true;
    else
    {
        saveBtn.enabled=false;
    }
}

…我不仅想检查一个单元格,还想检查几个单元格(如上面屏幕上的),现在它工作正常!谢谢!我可以用UIImageView代替复选标记(如屏幕上的交叉线)吗?我想这就是我需要的…如何将我的UIImageView与cell.accessoryView链接?使用图像创建UIImageView对象,然后将accessoryView设置为imageview(即,用imageview的变量名替换myAccessoryView)
- (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];
    }

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    cell.textLabel.textColor=[UIColor darkGrayColor];
    cell.textLabel.font= [UIFont fontWithName:@"Arial Rounded MT Bold" size:15.0];

    Scope_RepairMethod *scpObj=[repairMethodArr objectAtIndex:indexPath.row];
    cell.textLabel.text= scpObj.strRepairMethod;

    if([self.checkedIndexPath isEqual:indexPath])
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   // NSString *selID;

    UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];

    Scope_RepairMethod *scpObj=[repairMethodArr objectAtIndex:indexPath.row];

    if (newCell.accessoryType == UITableViewCellAccessoryNone)
    {
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
        [arrMethodsToBeStored addObject:scpObj.strRepairMethod];
    }
    else
    {
        newCell.accessoryType = UITableViewCellAccessoryNone;
        [arrMethodsToBeStored removeObject:scpObj.strRepairMethod];
    }
    NSLog(@"selected method arr==== %@",arrMethodsToBeStored);


// I want to enable my save button only if one or more values from table are selected

    if(arrMethodsToBeStored.count > 0)
        saveBtn.enabled=true;
    else
    {
        saveBtn.enabled=false;
    }
}