Сохранение текста в UITextView после прокрутки его с экрана - PullRequest
0 голосов
/ 05 июня 2011

Моя таблица имеет только 2 раздела.У меня есть UITextView в качестве подпредставления во 2-м разделе моей таблицы.и список возможных цитат в первом разделе.

У меня возникла проблема, когда пользователь выбирает конкретную цитату, которая «вставляется» в UITextView, например:

replyTextView.text = [NSString stringWithFormat:@"@%@ UserName writes... \n[\"%@\"]", replyPostCode,[separatedString objectAtIndex:indexPath.row]];

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
NSString *replyCellIdentifier = @"replyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    if ([indexPath section] == 0) {
        cell = [self CreateMultilinesCell:CellIdentifier];      
    }
    else if ([indexPath section] == 1) {
        //NSLog(@"TextField");
        cell = [self CreateMultilinesCell:replyCellIdentifier];     
        if ([indexPath row] == 0) {
            replyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 300, 150)];
            //replyTextView.adjustsFontSizeToFitWidth = YES;
            replyTextView.textColor = [UIColor blackColor];
            replyTextView.keyboardType = UIKeyboardTypeASCIICapable;
            replyTextView.returnKeyType = UIReturnKeyDefault;
            replyTextView.backgroundColor = [UIColor whiteColor];
            replyTextView.autocorrectionType = UITextAutocorrectionTypeNo; 
            replyTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;
            replyTextView.textAlignment = UITextAlignmentLeft;
            replyTextView.tag = 0;

            replyTextView.editable = YES;
            replyTextView.delegate = self;
            replyTextView.scrollEnabled = YES;

            //[replyTextView becomeFirstResponder];

            //replyTextView.clearButtonMode = UITextFieldViewModeNever;
            //[replyTextView setEnabled: YES];

            [cell.contentView addSubview:replyTextView];

            [replyTextView release];
            //cell.detailTextLabel.text = @"";
        }           
    }
}
//NSLog(@"%d", [indexPath section]);
if ([indexPath section] == 0) {
    cell.detailTextLabel.text = [separatedString objectAtIndex:indexPath.row];

}
return cell;
}

Мне просто интересно, каков наилучший способ сохранить текст в моем UITextView, когда пользователь прокручивает uitextview с экранаи обратно?

обновление

- (UITableViewCell*) CreateMultilinesCell :(NSString*)cellIdentifier
{

 //NSLog(@"Entering CreateMultilinesCell");
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                                reuseIdentifier:cellIdentifier] autorelease];

cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.font = [self SubFont];
cell.detailTextLabel.textColor = [UIColor colorWithRed:10.0/255 green:10.0/255 blue:33.0/255 alpha:1.0];
[cell setBackgroundColor:[UIColor clearColor]];//]colorWithRed:.98 green:.98 blue:.99 alpha:1.0]];
[self.tableView setBackgroundColor:[UIColor clearColor]];//colorWithRed:.94 green:.96 blue:.99 alpha:1.0]];
                                                         //NSLog(@"Exiting CreateMultilinesCell");
return cell;
}

1 Ответ

0 голосов
/ 05 июня 2011

Самое простое решение - использовать разные идентификаторы ячеек для двух типов ячеек.

Редактировать: я вижу, вы используете два разных типа, но вы не учитываете это при вызове dequeue.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...