Я создал страницу входа, которая содержит имя пользователя и пароль.Я создал одну пользовательскую ячейку, и она имеет одну метку и одно текстовое поле.И я создал одно сгруппированное табличное представление и использовал пользовательскую ячейку.На самом деле я создал успешно, но проблема в том, как я могу получить значения текстового поля для имени пользователя и пароля.Потому что я использовал только одно текстовое поле для обоих полей.Я не мог получить значения текстового поля правильно.Я всегда получаю последнее значение для обоих полей.Как я могу получить имя пользователя и текстовые значения пароля правильно?
Вот мой пример кода,
В пользовательской ячейке,
@interface CustomCell : UITableViewCell {
UILabel *userLbl;
UITextField *userTxt;
}
@property (nonatomic, retain) IBOutlet UILabel *userLbl;
@property (nonatomic, retain) IBOutlet UITextField *userTxt;
@end
В контроллере Root View
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
for(id currentObjects in nibObjects)
{
if([currentObjects isKindOfClass:[CustomCell class]])
{
cell = (CustomCell *) currentObjects;
}
}
}
if (indexPath.section == 0) {
if(indexPath.row == 0)
{
[[cell userLbl] setText:@"User Name:"];
cell.userTxt.tag = 0;
//self.userName = [[cell userTxt] text];
}
if (indexPath.row == 1) {
[[cell userLbl] setText:@"Pass Word:"];
cell.userTxt.secureTextEntry = YES;
//self.passWord = [[cell userTxt] text];
cell.userTxt.tag = 1;
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// Configure the cell.
return cell;
}
-(IBAction) submitAction : (id) sender
{
self.userName = [[cell userTxt] text];
self.passWord = [[cell userTxt] text];
[cell.userTxt resignFirstResponder];
NSLog(@"The user Name is %@", self.userName);
NSLog(@"The password is %@", self.passWord);
//Doesn't work
/* UITextField *txtField = (UITextField*)[cell viewWithTag:0];
self.userName = [txtField text];
UITextField *txtField1 = (UITextField*)[cell viewWithTag:1];
self.passWord = [txtField1 text];
NSLog(@"The user Name is %@", self.userName);
NSLog(@"The password is %@", self.passWord);*/
}
Вот мой снимок экрана с изображением,

Пожалуйста, помогите мне.
Спасибо.