私は uitableview がある場所で作業しており、フォームとして使用できるように、各セルに uitextfield を追加したいと考えています。このような uitextfields は約 15 個あります。しかし、画面にほとんどスペースがないため、一度に 5 行しか表示されず、スクロールすると他の行が表示されます。
これらすべての uitextfields からデータを取得しようとすると、表示されているものだけが取得され、他のものは null になります。再利用識別子を使用していないため、そうする必要があります。
以下は、CellfoRrowAtIndex の私のコードです。
editContactCell *tcell = (editContactCell*) [tableView dequeueReusableCellWithIdentifier:nil];
NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"editContactCell" owner:self options:nil];
tcell = (editContactCell *)[nib objectAtIndex:0];
tcell.accessoryType = UITableViewCellAccessoryNone;
tcell.selectionStyle = UITableViewCellSelectionStyleNone;
tcell.txtDetails.tag = indexPath.row+50;
if([dictClientDetails count]>0){
if(indexPath.section==0 && indexPath.row==0){
tcell.lblTitle.text = @"Mobile:";
tcell.txtDetails.placeholder = @"Mobile:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"Mobile"];
}
}
else if(indexPath.section==0 && indexPath.row==1){
tcell.lblTitle.text = @"Work:";
tcell.txtDetails.placeholder = @"Work:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"Work_number"];
}
}
else if(indexPath.section==1 && indexPath.row==0){
tcell.lblTitle.text = @"Email:";
tcell.txtDetails.placeholder = @"Email:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"Email"];
}
}
else if(indexPath.section==2 && indexPath.row==0){
tcell.lblTitle.text = @"IM1:";
tcell.txtDetails.placeholder = @"IM1:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"IM1"];
}
}
else if(indexPath.section==2 && indexPath.row==1){
tcell.lblTitle.text = @"IM2:";
tcell.txtDetails.placeholder = @"IM2:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"IM2"];
}
}
else if(indexPath.section==3 && indexPath.row==0){
tcell.lblTitle.text = @"Based In:";
tcell.txtDetails.placeholder = @"Based In:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"Location"];
}
}
else if(indexPath.section==3 && indexPath.row==1){
tcell.lblTitle.text = @"Address:";
tcell.txtDetails.placeholder = @"Address:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"Address"];
}
}
else if(indexPath.section==4 && indexPath.row==0){
tcell.lblTitle.text = @"Division:";
tcell.txtDetails.placeholder = @"Division:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"Division"];
}
}
else if(indexPath.section==4 && indexPath.row==1){
tcell.lblTitle.text = @"Department:";
tcell.txtDetails.placeholder = @"Department:";
if([dictClientDetails count]>0){
tcell.txtDetails.text = [dictClientDetails objectForKey:@"Department"];
}
}
}
return tcell;
次のようにデータを取得しようとしています。
NSLog(@"1 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]).txtDetails.text);
NSLog(@"2 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]).txtDetails.text);
NSLog(@"3 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]).txtDetails.text);
NSLog(@"4 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]]).txtDetails.text);
NSLog(@"5 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:2]]).txtDetails.text);
NSLog(@"6 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:3]]).txtDetails.text);
NSLog(@"7 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:3]]).txtDetails.text);
NSLog(@"8 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:4]]).txtDetails.text);
NSLog(@"9 %@",((editContactCell*)[tblvwEditContactDetails cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:4]]).txtDetails.text);
ただし、表示されている行だけがテキストフィールドを持ち、他の行はnullを返しています。