2016-06-25 2 views
0

설명을 위해 세 개의 텍스트 뷰가 필요한 테이블 뷰가 있습니다. 태그 1000이 포함 된 텍스트보기가 포함 된 프로토 타입 셀을 만들었습니다. 이 텍스트 뷰를 다시 사용하고 싶지만 스크롤 할 때 텍스트 뷰의 텍스트가 변경됩니다.테이블 뷰 내에서 다중 텍스트 뷰 관리

얼마 동안 Faraz는 haider textview의 위치를 ​​취하고 가끔 zaidi가 faraz의 위치를 ​​차지합니다.

나는 그들에게 고유 한 태그를 붙이려고 노력하지만 아직도 나를 돕지는 못한다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NSString *cellViewIdentifier = nil; 
long section = indexPath.section; 
UITableViewCell *cell; 

if(section == kSocialStatusSection) { 
    if(indexPath.row < socialResult.socialStatus.count){ 
     cellViewIdentifier = kCheckBoxItemCellViewIdentifier; 
     cellViewIdentifier = [cellViewIdentifier stringByAppendingString:langAppendString]; 
     cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellViewIdentifier]; 
     [cell setBackgroundColor:[UIColor clearColor]]; 

     SocialStatus * socialStatus = [socialResult.socialStatus objectAtIndex:indexPath.row]; 

        [cell setBackgroundColor:[UIColor clearColor]]; 
     UILabel *titleLabel = (UILabel *) [cell viewWithTag:kTagTitleCellLabel]; 

     //   NSMutableDictionary *obj = [socialStatusArray objectAtIndex:indexPath.row]; 
     [titleLabel setText:[LanguageUtilities isEnglishLanguage]?socialStatus.typeNameEn:socialStatus.typeNameAr]; 
     UIButton *checkBox = (UIButton *) [cell viewWithTag:kTagCheckButton]; 

     //   checkBox.selected = NO; 
     if([socialStatus.selected boolValue]) { 
      checkBox.selected = YES; 
     } 
     else{ 
      checkBox.selected = NO; 
     } 

    } else { 
     cellViewIdentifier = kDescriptionCellViewIdentifier; 
     cellViewIdentifier = [cellViewIdentifier stringByAppendingString:langAppendString]; 

     cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellViewIdentifier]; 

        [cell setBackgroundColor:[UIColor clearColor]]; 


     GCPlaceholderTextView *textArea = (GCPlaceholderTextView *)[cell viewWithTag:kTagDescriptionTextArea]; 
      textArea.placeholder =getLocalizedString(@"Description"); 

     textArea.delegate = self; 
      textArea.text = @"FARAZ"; 



    } 
} 
else if(section == kSocialStatusProblems){ 
    if(indexPath.row < socialResult.socialProblems.count){ 
     cellViewIdentifier = kCheckBoxItemCellViewIdentifier; 
     cellViewIdentifier = [cellViewIdentifier stringByAppendingString:langAppendString]; 
     cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellViewIdentifier]; 


        [cell setBackgroundColor:[UIColor clearColor]]; 

     SocialProblem * socialProblem = [socialResult.socialProblems objectAtIndex:indexPath.row]; 


     UILabel *titleLabel = (UILabel *) [cell viewWithTag:kTagTitleCellLabel]; 

     //   NSMutableDictionary *obj = [socialProblemsArray objectAtIndex:indexPath.row]; 
     [titleLabel setText:[LanguageUtilities isEnglishLanguage]?socialProblem.typeNameEn:socialProblem.typeNameAr]; 

     UIButton *checkBox = (UIButton *) [cell viewWithTag:kTagCheckButton]; 

     if([socialProblem.selected boolValue]) { 
      checkBox.selected = YES; 
     }else{ 
      checkBox.selected = NO; 
     } 

    } else { 
     cellViewIdentifier = kDescriptionCellViewIdentifier; 
     cellViewIdentifier = [cellViewIdentifier stringByAppendingString:langAppendString]; 

     cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellViewIdentifier]; 

        [cell setBackgroundColor:[UIColor clearColor]]; 

     GCPlaceholderTextView *textArea = (GCPlaceholderTextView *)[cell viewWithTag:kTagDescriptionTextArea]; 


     textArea.placeholder =getLocalizedString(@"Description"); 
     textArea.delegate = self; 
      textArea.text = @"Haider"; 



    } 
} 
else if(section == kProblemTypesSection){ 
    if(indexPath.row < socialResult.socialProblemsTypes.count){ 
     cellViewIdentifier = kCheckBoxItemCellViewIdentifier; 
     cellViewIdentifier = [cellViewIdentifier stringByAppendingString:langAppendString]; 
     cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellViewIdentifier]; 


        [cell setBackgroundColor:[UIColor clearColor]]; 

     SocialProblemsType * socialProblemType = [socialResult.socialProblemsTypes objectAtIndex:indexPath.row]; 


     UILabel *titleLabel = (UILabel *) [cell viewWithTag:kTagTitleCellLabel]; 

     //   NSMutableDictionary *obj = [problemTypeArray objectAtIndex:indexPath.row]; 
     [titleLabel setText:[LanguageUtilities isEnglishLanguage]?socialProblemType.typeNameEn:socialProblemType.typeNameAr]; 

     UIButton *checkBox = (UIButton *) [cell viewWithTag:kTagCheckButton]; 

     if([socialProblemType.selected boolValue]) { 
      checkBox.selected = YES; 
     }else 
     { 
      checkBox.selected = NO; 
     } 

    } else { 
     cellViewIdentifier = kDescriptionCellViewIdentifier; 
     cellViewIdentifier = [cellViewIdentifier stringByAppendingString:langAppendString]; 
     cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellViewIdentifier]; 

        [cell setBackgroundColor:[UIColor clearColor]]; 


     GCPlaceholderTextView * textArea= (GCPlaceholderTextView *)[cell viewWithTag:problemTypeTextViewTag];; 

     if (textArea != nil) { 
     textArea= (GCPlaceholderTextView *)[cell viewWithTag:problemTypeTextViewTag]; 
     }else 
     { 
     textArea= (GCPlaceholderTextView *)[cell viewWithTag:kTagDescriptionTextArea]; 
      [textArea setTag:problemTypeTextViewTag]; 
     } 
      textArea.placeholder =getLocalizedString(@"Description"); 

     textArea.delegate = self; 
      textArea.text = @"zaidi"; 




    } 
} 
return cell;} 
+0

여기를 참고하십시오 http://stackoverflow.com/questions/26617151/how-come-my-uitableview-is-repeating-rows-after-5rows 및 기타 여러 가지. 테이블 셀은 재사용되므로 각 셀에 고유 한 데이터를 배열 (또는 행으로 인덱싱 할 수있는 다른 구조)에 보관해야합니다. 또한 동일한 수퍼 뷰를 사용하여 다른 텍스트 필드에 다른 태그를 사용해야합니다. – danh

+0

다른 태그로, 당신은 내가 textview 및 각 태그를 고유하게 만드는 세 가지 프로토 타입 셀을 만들어야한다고 말하는 건가요? textview의 양이 증가한다면 그것은 쓸모가 없습니까? –

+0

세 개의 텍스트보기가있는 셀이 하나있을 수 있지만 각 텍스트보기의 태그 속성을 할당하려는 경우 해당 정수 값은 고유해야합니다. – danh

답변

0

각 셀의 문자열을 포함하는 NSMutableArray 개체로 할 수 있습니다. 빈 문자열로 배열을 채우고이 정보를 사용하여 텍스트 필드를 채워야합니다. 당신은 뷰 컨트롤러 내에서 프로그래밍을하고있는 때문에 그것은

textView.text = [textViewStringsArr objectAtIndex:indexPath.row]; 

, 같은 될 것입니다, 당신은 당신의 텍스트 뷰의 대표로 뷰 컨트롤러를 설정해야합니다. 할 수 있습니다

-(void)textViewDidEndEditing:(UITextView *)textView { 
UITableViewCell *cell = (UITableViewCell*)textField.superview; 

NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; 

... Since you've the index path, you can map it to an array. 

[textViewStringsArr replaceObjectAtIndexPath:indexPath withObject:textView.text]; 
} 

이것은 기본적인 아이디어입니다. 빈 문자열의 가변 배열로 시작하고 원본 텍스트를 새 텍스트로 바꾸어 텍스트보기가 업데이트 될 때마다 수정하십시오. 희망이 도움이됩니다.

관련 문제