我使用自定义单元格表视图。在此每个单元格包含文本视图和编辑按钮

时间:2012-02-22 10:30:26

标签: iphone ios4

我为编辑按钮分配了自定义操作。

“我的查询是,当我按下编辑按钮时,它将调用customaction方法(此方法的目的是编辑textview中的文本并将当前值存储在数组中)。

我的要求是经过再次编辑,它将回到didselctrowatindex方法。如何从习惯方法回到didselctrowatindex。我的代码是

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

    //The user is selecting the cell which is currently expanded
    //we want to minimize it back

    if(selectedIndex == indexPath.row)
    {
        selectedIndex = -1;

       [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

        return;
    }

    //First we check if a cell is already expanded.

    //If it is we want to minimize make sure it is reloaded to minimize it back
  if(selectedIndex >= 0)
    {

        NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
        selectedIndex = indexPath.row;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];        

    }

    //Finally set the selected index to the new selection and reload it to expand
    selectedIndex = indexPath.row;

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

    [button setBackgroundImage:[UIImage imageNamed:@"slider2.png"] forState:UIControlStateNormal]; 

    labelname.textColor = [UIColor yellowColor];

    passionnameslabel.textColor=[UIColor yellowColor];

    textview1.font = [UIFont fontWithName:@"Helvetica" size:15.0f];

    textview1.text = [textview1.text stringByAppendingString:[mylifearray objectAtIndex:indexPath.row]];
    textview1.delegate=self;

    [pes setInteger:selectedIndex forKey:@"selected"];

    [editbutton addTarget:self action:@selector(customActionPressed:)forControlEvents:UIControlEventTouchUpInside];

        [editbutton setBackgroundImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateNormal]; 
}
-(void)customActionPressed
{



    textview1.inputView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];


    textview1.editable=YES;

     mylifearray=[NSMutableArray arrayWithArray:[pes objectForKey:@"mylifearray"]];

     [mylifearray removeObjectAtIndex:selectedIndex];

     [mylifearray insertObject:textview1.text atIndex:selectedIndex];

         [pes setObject:mylifearray forKey:@"mylifearray"];

}

任何身体都可以提前帮助谢谢

1 个答案:

答案 0 :(得分:0)

您可以明确调用委托方法:

[self tableView:self.tableView didDeselectRowAtIndexPath:indexPath];

或者,您也可以编写一个方法,执行与didDeselectRowAtIndexPath中相同的操作,并在需要时调用它。