2012-02-21 23 views
0

まず第一に、いくつかのタイトルが同じように見えることがわかります。私はそれらをチェックしたが、私が尋ねるものは特定の問題である。カスタムUITableViewにあるUITextFieldからデータを読み取る方法

私がしたいこと:作成されたメールとパスワードを含むログインテーブル。 UITextViewのUITextfields。これらのデータをNSString変数ポインタに取り込んで、それ以降の処理をしたいだけです。

私は以下のようにCustomCellという名前のカスタムセルクラス、持っている:

#import "CustomCell.h" 
#import "QuartzCore/QuartzCore.h" 

@implementation CustomCell 
@synthesize textfield; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     textfield = [[UITextField alloc] initWithFrame:CGRectMake(5, 7, 160, 20)]; 
     textfield.textColor = [UIColor blackColor]; 
     textfield.font = [UIFont systemFontOfSize:14]; 
     [self.contentView addSubview:textfield]; 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:NO animated:NO]; 
    // Configure the view for the selected state. 
} 

- (void)dealloc { 
    [super dealloc]; 
} 
@end 

をそして私は、私はあなたの下のカスタム・テーブルを使用するのViewControllerが私のtableView cellForRowAtIndex方法を見ることができる持っています。同じクラスの

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *CellIdentifier = @"Cell"; 
    [tableView.layer setCornerRadius:10.0]; 

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

     cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];} 

     switch (indexPath.row) { 
      case 0: 
       cell.textfield.placeholder = @"Email"; 
       break; 
      case 1: 
       cell.textfield.placeholder = @"Password"; 
       cell.textfield.tag = 0; 
       break; 
    } 

    return cell; 
} 

そして最後に以下の私は

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0]; 
CustomCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // ERROR!!! 
NSString *userpassword = cell.textfield.text; 

エラーでメール&パスワードを読みしようとしています:不明な受信機タイプのtableView:

注意同じラインで:
ClassMethod + cellforrowatindexpathが見つかりません。戻り値のデフォルトはidです。

私が間違っているのを見ましたか?

+0

tableView cellForRawAtIndexPathメソッドでタグを無視してください。 – karaca

+0

タグを無視するのはなぜですか?実際にここでタグを使うのは悪い考えではありません。あなたの電子メールのテキストフィールド1とパスワードのテキストフィールドにタグを付けます。2.これらのテキストフィールドの両方に対するビューコントローラをデリゲートにし、 ' - (BOOL)textFieldShouldReturn:(UITextField *)textField'を実装します。このメソッドでは、どのテキストフィールドが編集を終了したかを区別するためにタグを読み取ります。値をつかみ、コントローラーのivarに保存します。あなたの質問に対する本当の答えは、**表形式のデータを表示する必要がない場合は、テーブルビューを使用しないでください**と思うので、答えとして入力しません。 – lawicko

答えて

3
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0]; 
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath]; // Add This instead 
NSString *userpassword = cell.textfield.text; 
0

ViewControllerはUIViewまたはUITableViewControllerを継承していますか?これは、Table Viewと同じコントローラ上でtableViewを呼び出すことを前提としています。

0

Yuは、データソースおよびデリゲートメソッドの外でtableViewを使用することはできません。あなたのインターフェイス定義であなたのテーブルビューの名前は何ですか?それを使用してください。

関連する問題