2012-05-18 2 views
0

이 때 텍스트가 여기내가 너무

텍스트 필드 (9)에 표시되는 1 내가 텍스트 필드에 텍스트를 입력하고하는 것은 내가 한 짓을 몇 가지 코드가 그것을 다른 텍스트 필드에 동일한 텍스트를 diplaying되어 하나 개의 필드에 텍스트를 입력하고있는 동안 tableview 셀에 텍스트 필드를 만듭니다.

은 내가 cellforRowatintexpath 방법

- (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;} 

아래 .like있는 tableview 셀의 텍스트 필드를 추가하고 여기에 어쩌면 당신은 텍스트 필드에 일부 함께 IBOutlet 설정 한 방법 getTextFieldValue 방법

- (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); 
} } 
+0

그리고 질문은 ... :) –

+0

내가 그것을 여러 텍스트 필드에 표시 한 텍스트 필드에 텍스트를 입력하고있는 동안 ..... – iosDev

+0

지금 내 질문은 분명 – iosDev

답변

0

(가) 문제를 유지하는 것입니다있다.

각 행마다 다른 cellIdentifier를 사용할 수 있습니다. 솔루션을 얻을 수있는 진술 만 변경하십시오.

위의 방법으로이 문제를 해결하십시오. 나는 같은 문제에 직면했다 & 나는이 방법으로 해결한다. 도움이되기를 바랍니다.

NSString *CellIdentifier = [NSString stringWithFormat:@"cellidentifier-%d",indexPath.row]; 
+0

나는 그것이 당신을 위해 일할 것이라고 확신합니다. – Jasmit

+0

오류 이니셜 라이저 요소를주는 것은 일정하지 않습니다 ........ – iosDev

+0

지금해야 할 일 – iosDev

0

입니까? 너? 모든

1

먼저,이처럼 getTextFieldValue 방법을 다시 작성하십시오

- (void)getTextFieldValue:(UITextField *)textField { 
    NSLog(@"%d--->%@", textField.tag, textField.text); 
} 

당신은 그것을 다시 사용할 때에도, 셀에 UITextFields를 계속 추가. 이 코드를 if 문 안에 넣으십시오.

그래도 매번 텍스트 필드의 텍스트를 nil로 설정해야합니다. 그렇지 않으면 여전히 대기열에있는 셀에있을 것입니다 (스크롤 할 때). 이 같은

뭔가 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

static NSString *CellIdentifier = @"myCell"; 
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if(cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(7.0, 10.0, 160.0, 44.0)]; 
    //TODO: Set up nameLabel here 
    [cell.contentView addSubview: nameLabel]; 
    [nameLabel release]; 

    UITextField *tv = [[UITextField alloc] init]; 
    tv.font = [UIFont boldSystemFontOfSize:12]; 
    [tv setDelegate:self]; 
    [tv addTarget:self action:@selector(getTextFieldValue:) forControlEvents:UIControlEventEditingDidEnd]; 
    [cell.contentView addSubview:tv]; 
    [tv release]; 
} 

UILabel *nameLabel = (UILabel *)[cell viewWithTag:1]; 
nameLabel.text = [labels objectAtIndex:indexPath.row]; 
[nameLabel sizeToFit]; 

return cell; 
} 
관련 문제