0

で、そのような行に触れたときに、その行UITableViewのプロパティを編集できるようにしたいと思います。cell.textLabel.text

つまり、編集モードに入るのではなく、行に直接触れて編集できるようにしたいと思います。

どうすればこれを実装できますか?

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

    static NSString *CellIdentifier = @"Cell";

    CMTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CMTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    int tagsCount = [[currentComic Tags] count];

    [[cell textField] setTag:[indexPath row]];
    [[cell textField] setText:[tagsDisplayName objectAtIndex:[indexPath row]]];

    return cell;
}

そしてこれはサブクラスCMTableViewCellです:

...

-(void)viewDidLoad
{    
    textField = [[UITextField alloc] init];
    [textField setFrame:CGRectMake(5,5,50,400)];
    [self addSubview:textField];
}
4

2 に答える 2

1

UITextFieldサブビューとして境界線なしで追加します。サブビューに追加する前に-TagnubmerをUITextFieldfromメソッドに設定indexPath.rowtableview cellForRowAtIndexPathます。UITextFieldDelegateユーザーがデータを入力したとき- 「戻る」ボタンが押されたときのメソッドでデータを保存します。残念ながら、現在Windowsを使用しているため、コードを提供することはできません。ホームこれは役立ちます

更新:データソースのデータを変更するために必要なタグ番号。UITextFieldの[戻る]ボタンを押すと、UITextFieldからこのタグ番号でUITableViewCellを取得することにより、変更を保存できます。

于 2012-08-24T12:10:32.060 に答える
0

簡単だ:

- (void)tableView:(UITableView *)tableView
                             didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.textLabel.text = @"...";
}

アップデート

- (void)tableView:(UITableView *)tableView
                             didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITextField *textField = [[UITextField alloc] init];
    [textField setTag:[indexPath row]];
    [tagsTableView addSubview:textField];
    FreeAndNil(textField);
}
于 2012-08-24T11:52:40.127 に答える