1

現在、ユーザーが複数のセルのコンテンツを編集できるようにしようとしています。更新されると、データは Web サービスに送信されます。

私が読んだ限りでは、「削除」と「追加」行しかありません。セルのコンテンツを編集する方法に関するガイドやチュートリアルが見つからないようです。

あなたの提案やアドバイスは大歓迎です。

if (editingStyle == UITableViewCellEditingStyleDelete) {
    // Delete the row from the data source
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}   
else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}   
4

1 に答える 1

3

セルの内容を直接編集することはできません。コンテンツを編集する必要がある場合は、サブビューとしてUITextFieldまたはセルに追加します。UITextViewそしてそれらにアクセスします。

編集:以下のようにテキストフィールドを追加できます:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"cellIdentifier";

    UITableViewCell *cell;
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        // ADD YOUR TEXTFIELD HERE
        UITextField *yourTf = [[UITextField alloc] initWithFrame:CGRectMake(0, 5, 330.0f, 30)];
        [yourTf setBackgroundColor:[UIColor clearColor]];
        yourTf.tag = 1;
        yourTf.font = [UIFont fontWithName:@"Helvetica" size:15];
        yourTf.textColor = [UIColor colorWithRed:61.0f/255.0f green:61.0f/255.0f blue:61.0f/255.0f alpha:1.0f];
        yourTf.delegate = self;
        [cell addSubview:yourTf];

    }

    // ACCESS YOUR TEXTFIELD BY REUSING IT
    [(UITextField *)[cell viewWithTag:1] setText:@"YOUR TEXT"];

    return cell;
}

UITextField デリゲートを実装すると、この UITextField を使用してセルの内容を編集できます。

お役に立てば幸いです。

于 2013-08-05T11:17:07.997 に答える