如何在iPhone SDK中触摸时可以编辑tableviewcell文本?

时间:2011-01-13 06:51:33

标签: iphone cocoa-touch uitableview ios-4.2

在我的iPhone应用程序中,我有一个表视图。

我希望当用户选择(或基本上触摸)tableview的单元格时,他/她应该能够编辑单元格内容。

我该怎么做?

2 个答案:

答案 0 :(得分:3)

@PARTH为了让您的UITableView单元格可编辑,我建议您为您的单元格提供文本字段....

例如: - 在

-(UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier withIndexPath:(NSIndexPath *)indexPath {


    CGRect cellRectangle = CGRectMake (0, 10, 300, 70); 
    CGRect Field1Frame = CGRectMake (10, 10, 290, 70);
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellRectangle reuseIdentifier:identifier] autorelease];
    UITextField *textField;


    //Initialize Label with tag 1.

    textField = [[UITextField alloc] initWithFrame:Field1Frame];

    textField.tag = 1;
    [cell.contentView addSubview:textField];

[textField release];
    return cell;
}

并在您的cellForRowAtIndexPath方法中//配置单元格。

 UITextField *txtTemp = (UITextField *)[cell.contentView viewWithTag:1];

在你的tableview中相应地使用它,否则隐藏它.....希望它会帮助你!!

答案 1 :(得分:0)

您需要在表格单元格中放置文本字段,请使用此link.