我有一个UITableView的customCell的UITextField。在UITextField的点击手势中,我需要在UITableViewCell的右侧显示复选标记

我有一个UITableView的customCell的UITextField。在UITextField的点击手势中,我需要在UITableViewCell的右侧显示复选标记,uitableview,Uitableview,我有一个UITableView的customCell的UITextField。 在UITextField的点击手势中,我需要在UITableViewCell的右侧显示复选标记 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { PreferenceCellWithTextBox *cell = (PreferenceCellWithTe

我有一个UITableView的customCell的UITextField。 在UITextField的点击手势中,我需要在UITableViewCell的右侧显示复选标记

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

PreferenceCellWithTextBox *cell = (PreferenceCellWithTextBox *)[tableView dequeueReusableCellWithIdentifier:@"PreferenceCellIdentifier"];

if (cell == nil)
{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PreferenceCellWithTextBox"
        owner:nil
        options:nil];

    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[UITableViewCell class]])
        {

            cell=(PreferenceCellWithTextBox *)currentObject;
            break;
        }
    }

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


        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(forwardToDidSelect:)];
        [cell.userIdTextField addGestureRecognizer:tap];

}

return cell;
}
 -(void)forwardToDidSelect:(UITapGestureRecognizer *)tap
{

[self tableView:self.userIdSuggestiontableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

}
在这里,我写的是轻拍手势。它只会被调用一次。不应该这样。每当我触摸UITableViewCell上的UITextField时,就会调用它

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

PreferenceCellWithTextBox *cell = (PreferenceCellWithTextBox *)[tableView dequeueReusableCellWithIdentifier:@"PreferenceCellIdentifier"];

if (cell == nil)
{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PreferenceCellWithTextBox"
        owner:nil
        options:nil];

    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[UITableViewCell class]])
        {

            cell=(PreferenceCellWithTextBox *)currentObject;
            break;
        }
    }

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


        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(forwardToDidSelect:)];
        [cell.userIdTextField addGestureRecognizer:tap];

}

return cell;
}
 -(void)forwardToDidSelect:(UITapGestureRecognizer *)tap
{

[self tableView:self.userIdSuggestiontableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

}
在这里,我为did select行编写了代码。在选择任何行时,我要显示复选标记。并从上一行中删除复选标记

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


if(self.checkedIndexPath)

{
    PreferenceCellWithTextBox* uncheckCell =(PreferenceCellWithTextBox *) [tableView
                                    cellForRowAtIndexPath:self.checkedIndexPath];

    uncheckCell.accessoryType = UITableViewCellAccessoryNone;

}
if([self.checkedIndexPath isEqual:indexPath])

{
    self.checkedIndexPath = nil;
}
else
{

    PreferenceCellWithTextBox* cell = (PreferenceCellWithTextBox*)[tableView cellForRowAtIndexPath:indexPath];



    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    self.checkedIndexPath = indexPath;


}

}

再说一次,没有提到你到目前为止尝试过的东西。很抱歉,你不会得到这样的帮助的。嗨,苏菲安,我已经添加了密码。