When I am entering text in textfield 1 that text is also displayed in textfield 9.
here is some code what i did to create textfield in tableview cell.
i added textfield in tableview cell .like below in cellforRowatintexpath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"myCell";
//UILabel* nameLabel = nil;
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
UILabel *titleLbl = (UILabel *)[cell viewWithTag:1];
[titleLbl removeFromSuperview];
}
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake( 7.0, 10.0, 160.0, 44.0 )];
nameLabel.text = [labels objectAtIndex:indexPath.row];
nameLabel.font = [UIFont boldSystemFontOfSize:12];
nameLabel.lineBreakMode = UILineBreakModeWordWrap;
nameLabel.tag =1;
nameLabel.numberOfLines =0;
[nameLabel sizeToFit];
CGSize expectedlabelsize = [nameLabel.text sizeWithFont:nameLabel.font constrainedToSize:nameLabel.frame.size lineBreakMode:UILineBreakModeWordWrap];
CGRect newFrame =nameLabel.frame;
newFrame.size.height =expectedlabelsize.height;
[cell.contentView addSubview: nameLabel];
[nameLabel release];
//adding textfield to tableview cell.
tv = [[UITextField alloc] initWithFrame:CGRectMake(nameLabel.frame.origin.x+nameLabel.frame.size.width+2, 10.0, cell.contentView.bounds.size.width, 30)];
tv.tag = indexPath.row + 2;
//tv.text =[labels objectAtIndex:indexPath.row];
tv.font = [UIFont boldSystemFontOfSize:12];
//this method will take text from textfield of tableview cell using their individual tag
[tv addTarget:self action:@selector(getTextFieldValue:) forControlEvents:UIControlEventEditingDidEnd];
[cell.contentView addSubview:tv];
[tv setDelegate:self];
[tv release];
return cell;}
and here is the method getTextFieldValue method
- (void) getTextFieldValue:(UITextField *)textField{
if (textField.tag == 2) {
//NSString *value1 = [NSString stringWithFormat:@"%@",textField.text];
//NSLog(@"value1 is %@",value1);.
NSLog(@"2--->%@",textField.text);
}else if(textField.tag == 3){
NSLog(@"3--->%@",textField.text);
}else if(textField.tag == 4){
NSLog(@"4--->%@",textField.text);
}
else if(textField.tag == 5){
NSLog(@"5--->%@",textField.text);
}
else if(textField.tag == 6){
NSLog(@"6--->%@",textField.text);
}
else if(textField.tag == 7){
NSLog(@"7--->%@",textField.text);
}
else if(textField.tag == 8){
NSLog(@"8--->%@",textField.text);
}
else if(textField.tag == 9){
NSLog(@"9--->%@",textField.text);
}
else if(textField.tag == 10){
NSLog(@"10--->%@",textField.text);
}
else if(textField.tag == 11){
NSLog(@"11--->%@",textField.text);
}
else if(textField.tag == 12){
NSLog(@"12--->%@",textField.text);
} }
That is the retain problem is there.
You can take different cellIdentifier for each row. Only change one statement you get your solution.
Solve this problem with above method. i was facing same problem & i solve with this method.
I hope this will help you.