ログインボタンのクリック時に UITableviewCell 値を取得したい。ユーザーがログインボタンを押すと、最初のセル(電子メール)と2番目のセル(パスワード)の値を取得したいと思います。私を助けてください。
ありがとう!シャイレシュ
ログインボタンのクリック時に UITableviewCell 値を取得したい。ユーザーがログインボタンを押すと、最初のセル(電子メール)と2番目のセル(パスワード)の値を取得したいと思います。私を助けてください。
ありがとう!シャイレシュ
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);
}
セルにサブビューとして 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);
これがあなたを助けることを願っています:)
-(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
}
}
最も簡単な方法は、以下のように、textField デリゲートの別の文字列に textField 値を保存することです。
-(void)textFieldDidEndEditing:(UITextField *)textField{
stringEmail = textField.text;
}
タグを設定して、両方に対して実行します。
ありがとうございました。