2016-06-25 2 views
0

У меня есть табличное представление, для которого требуется три текста для описания. Я сделал прототип ячейки, содержащей текстовое представление с тегом 1000. Я хочу повторно использовать это текстовое представление, но текст текстового обзора меняется, когда я прокручиваю.Управление множественным текстом внутри tableview

Некоторое время Фарац занимал позицию haider textview и когда-то заиди занимал позицию 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-5-rows и многие другие. Ячейки таблицы повторно используются, поэтому уникальные для каждого данные должны храниться в массиве (или какой-либо другой структуре, которая может быть проиндексирована по строке). Кроме того, вы должны использовать разные теги для разных текстовых полей с тем же супервидом. – danh

+0

по разному тегу, вы хотите сказать, что мне нужно создать три разных ячейки прототипа для текстового просмотра и сделать каждый тег уникальным? Неужели это бесполезно, если количество текстовых просмотров увеличивается? –

+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]; 
} 

Это была бы основная идея. Начните с изменяемого массива пустых строк и изменяйте их каждый раз, когда текстовое представление обновляется путем замены исходного текста на новый текст. Надеюсь это поможет.

Смежные вопросы