0

ログインボタンのクリック時に UITableviewCell 値を取得したい。ユーザーがログインボタンを押すと、最初のセル(電子メール)と2番目のセル(パスワード)の値を取得したいと思います。私を助けてください。

ここに画像の説明を入力

ありがとう!シャイレシュ

4

6 に答える 6

3

Please try to use this one.I hope it may help you. But you should assign tag 1 to email and 2 to password text field.

-(IBAction)loginBtnPressed:(IBAction)sender
{
   UITableViewCell *emailCell = [self.tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 
                                  UITableViewCell *passwordCell = [self.tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]] ;//pass
    UITextField *emailTxtFLd = (UITextField *)[emailCell viewWithTag:1];
    UITextField *passwordTxtFLd = (UITextField *)[passwordCell viewWithTag:2];

    NSLog(@"Email : %@",emailTxtFLd.text);
    NSLog(@"Password : %@",passwordTxtFLd.text);
}
于 2013-05-07T13:04:57.810 に答える
2

セルにサブビューとして textFiled を追加するときに、次のように textFiled にタグを設定します。

[textField setTag:-1];

そして、textFiled からテキストを取得する場合は、次の手順に従います。

// Getting email
CustomCell *tableCell = (CustomCell*)[myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

UITextField *myTextField = (UITextField *)[tableCell viewWithTag:-1];

NSString *emailString = [myTextField text];
NSLog(@"~~~~ email: %@", emailString);

// Getting Password
tableCell = [myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];

myTextField = (UITextField *)[tableCell viewWithTag:-1];

NSString *passwordString = [myTextField text];
NSLog(@"~~~~ password: %@", passwordString);

これがあなたを助けることを願っています:)

于 2013-05-07T13:00:25.560 に答える
0
-(void)ActivateLogin{


NSIndexPath *tmpIndexPath0 = [NSIndexPath indexPathForRow:0 inSection:0];
NSIndexPath *tmpIndexPath1 = [NSIndexPath indexPathForRow:1 inSection:0];

CustomCell *cellCopy0 =(CustomCell*) [tableViewName cellForRowAtIndexPath:tmpIndexPath0];
CustomCell *cellCopy1 =(CustomCell*) [tableViewName cellForRowAtIndexPath:tmpIndexPath1];


NSString *strEmail = @""; NSString *strPassword = @"";

strEmail = cellCopy0.tf.text;
strPassword = cellCopy1.tf.text;

if(![strEmail isEqualToString:@""] && ![strPassword isEqualToString:@""]){

... //Do what you want to do with the data

}
else{
//Alert user to enter credentials
}

}
于 2013-05-07T12:49:56.470 に答える
0

最も簡単な方法は、以下のように、textField デリゲートの別の文字列に textField 値を保存することです。

-(void)textFieldDidEndEditing:(UITextField *)textField{
 stringEmail = textField.text;
}

タグを設定して、両方に対して実行します。

ありがとうございました。

于 2013-05-07T12:53:35.013 に答える