2016-06-25 7 views
0

私は説明のために3つのtextviewを必要とするテーブルビューを持っています。私はタグ1000のテキストビューを含むプロトタイプのセルを作った。 私はこのテキストビューを再利用したいが、私がスクロールするときにテキストビューのテキストが変わる。テーブルビュー内で複数のテキストビューを管理する

時々、ファラズはハイダーのテキストビューを取って、いつかはファジィの位置を取る。

私はそれらにもユニークなタグをつけようとしますが、まだそれは私を助けません。

- (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のための3つの異なるプロトタイプのセルを作成し、各タグを一意にする必要があると言うことを意味するのですか?テキストビューの量が増えると無駄ではないですか? –

+0

3つのテキストビューを持つ1つのセルがありますが、各テキストビューのタグプロパティを割り当てる場合、それらの整数値は一意でなければなりません。 – 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]; 
} 

これは基本的な考えです。テキストの表示が更新されるたびに、元のテキストを新しいテキストに置き換えて、空の文字列の可変配列を変更してから変更します。お役に立てれば。

関連する問題