2011-07-05 11 views

答えて

1

enter code hereテキストフィールドの値を格納するNSMutableArrayを追跡する必要があります。 @ ""初期値を作る。テキストフィールドをセルに挿入すると、配列の適切な値から値のフォームを取得します。

テキストフィールドが終了し、[いいえ、まだ解決されていない配列

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
    { 
    UITableViewCell *cell=(UITableViewCell *)textField.superview; 
    NSIndexPath *indexPath = [table indexPathForCell:cell]; 

    NSMutableArray *rows=[sectionArray objectAtIndex:[indexPath section]]; 
    NSString *string=[rows objectAtIndex:indexPath.row]; 
    string=textField.text; 
    [[sectionArray objectAtIndex:[indexPath section]]replaceObjectAtIndex:[indexPath row] withObject:string]; 
    [textField resignFirstResponder]; 
    return YES; } 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCellId]; 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier: myCellId]; 

    CGRect textFieldFrame; 
    CGRect labelFrame; 
    labelFrame = CGRectMake(cell.frame.origin.x+45, cell.frame.origin.y+3, labelWidth, cell.bounds.size.height-5); 
    textFieldFrame = CGRectMake(cell.frame.origin.x+labelWidth+15, cell.frame.origin.y+12 ,cell. 
    UILabel *label = [[UILabel alloc]initWithFrame:labelFrame]; 

    UITextField *textField = [[UITextField alloc]initWithFrame:textFieldFrame]; 
    textField.keyboardType=UIKeyboardTypeNumberPad; 
    textField.delegate = self; 
    textField.text = [[sectionArray objectAtIndex:[indexPath section]]objectAtIndex:[indexPath row]]; 


    [cell addSubview:label]; 
    [cell addSubview:textField]; 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 
} 
+0

あなたの答えはありがたいですが、このメソッドはテキスト入力後に呼び出されますが、スクロール後に以前に入力した値をフェッチして、その値をTextFieldに再度表示する方法はありますか? –

+0

セルが作成されると、それはテキストフィールドを含み、そのテキストフィールドは配列の正しいエントリからその値をプリロードします。だから、テーブル内のセルがどの行にあるのかを調べ、その値を配列から取得してください(デフォルト値のすべての場所で@ ""をプリロードすることを忘れないでください)。 – James

+0

しかし、スクロールしている間に、表示されているテキストフィールドの名前をクリックすることなく知ることができますか? –

0

スクロールすると、テーブルビューはダイナミックにセルを作成して破棄し、メモリに保存するためです。この問題を解決する方法がまだ分かっていない場合は、私に知らせてください。解決策を見つけるのを手助けします。

+0

の値をテキストフィールド格納するために、このような代を行います。 –

関連する問題