2016-05-29 1 views
0

Я пытаюсь загрузить UITextView в UItableViewCell с данными, но не могу установить текст. UITextViewDelegate также устанавливается и прикрепляется к контроллеру просмотра. Текстовая строка не пуста, поскольку я проверил ее с помощью отладчика.Не удается установить текст в текстовом виде в моей таблице tableView

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier]; 
    //CommentCell is my custom cell with textView. 
    CommentCell *commentsCell = (CommentCell*)[tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier forIndexPath:indexPath]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CommentCellIdentifier]; 
    } 

    //Setting the images for all buttons in service row. 
    [commentsCell.deletecomment setImage:deleteComment forState:UIControlStateNormal]; 
    [commentsCell.editcomment setImage:editComment forState:UIControlStateNormal]; 

    commentsCell.deletecomment.layer.borderColor = [UIColor blackColor].CGColor; 
    commentsCell.editcomment.layer.borderColor = [UIColor blackColor].CGColor; 
    NSInteger commentIndex = 2; 

    //CommentsArray is NSArray with data. 
    [commentCell.comments setText:[NSString stringWithFormat:@"%@",[[commentsArray objectAtIndex:indexPath.row] objectAtIndex:commentIndex]]]; 

    return cell; 
} 
+0

Вы уже зарегистрировали эту ячейку или добавили ее в раскадровку? Вы должны остановиться в своем 'if (cell == nil) {..}' и увидеть его false – orxelm

+0

Лучше использовать пользовательскую ячейку – user3182143

+0

Да. Я добавил его в раскадровку и назначил ему свой собственный класс ячеек. Мне не нужно регистрироваться, поскольку я делаю то же самое в своих других контроллерах представлений. Единственное различие заключается в том, что я использую UITextView вместо UIlabel. – WasimSafdar

ответ

0

Я использовал неправильный CellName. Просто заменил «commentCell» на «commentsCell», и все начинает работать.

[commentsCell.comments setText:[NSString stringWithFormat:@"%@",[[commentsArray objectAtIndex:indexPath.row] objectAtIndex:commentIndex]]];`enter code here` 
0

(Почему установить commentsCell и вернуть клетки в конце?)
Проверить фрейм TextView и атрибуты текста, и убедитесь, что оно может быть показано или видели;

0

Попробуйте изменить эту строку:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier]; 

этой линии:

CommentCell *cell = (CommentCell*)[tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier]; 
Смежные вопросы