2013-07-18 4 views
0

Я добавляю серию текстовых представлений внутри прокрутки в прокрутку. Я могу нарисовать первый текстовый вид в виде прокрутки. Когда я пытаюсь добавить второе текстовое представление, связанное представление прокрутки вычерчивается, текстовое представление не добавляется. Может ли кто-нибудь указать, что я здесь делаю неправильно?UITextView в UIScrollView как внутри другого UIScrollView

for (int i = 0; i < numberOfViews; i ++) { 

    CGFloat xOrigin = i * 230; 
    CGRect textRect = CGRectMake(xOrigin, 0, 210, 250); 
    CGRect imageRect = CGRectMake(xOrigin, 30, 210, 5); 
    CGRect subscrollRect = CGRectMake(xOrigin, 40, 210, 250); 

    _image1 = [[UIImageView alloc] initWithFrame:imageRect]; 
    _image1.image = [UIImage imageNamed:@"horizontal_line_02.png"]; 

    if (i == 0) { 
     _textView1 = [[UITextView alloc] initWithFrame:textRect]; 
     _textView1.delegate = self; 
     _textView1.userInteractionEnabled = NO; 
     _textView1.text = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; 
     _subScrollView1 = [[UIScrollView alloc] initWithFrame:subscrollRect]; 
     [_subScrollView1 setContentSize:CGSizeMake(210, 500)]; 
     [_subScrollView1 addSubview:_textView1]; 
     [_textScrollView addSubview:_subScrollView1]; 
     [_textScrollView addSubview:_image1]; 
    } 
    else if (i == 1) { 
     _textView2 = [[UITextView alloc] initWithFrame:textRect]; 
     _textView2.delegate = self; 
     _textView2.userInteractionEnabled = YES; 
     _textView2.text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent accumsan elementum tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer sapien turpis, laoreet id ullamcorper sed, accumsan id ligula. Etiam euismod, augue sed porta eleifend, mauris dolor scelerisque velit, ac facilisis libero elit et arcu. Morbi ligula libero, porta id leo ut, convallis adipiscing enim."; 
     _subScrollView2 = [[UIScrollView alloc] initWithFrame:subscrollRect]; 
     [_subScrollView2 setContentSize:CGSizeMake(210, 500)]; 
     [_subScrollView2 addSubview:_textView2]; 
     [_textScrollView addSubview:_subScrollView2]; 
     [_textScrollView addSubview:_image1]; 
    } 
+0

Почему Вы добавляете TextView в свитке и снова в прокрутке. Не нужно добавлять два прокрутки, вам просто нужно отключить редактируемое свойство и включить взаимодействие с пользователем ... Он автоматически добавит прокрутку в ваш текст! – Ajay

+0

Aha! Я установил редактируемый свойство отключено, но не включил взаимодействие с пользователем. Спасибо. – Barry

+0

Примечание: scrollEnabled также должен быть установлен на YES. – Barry

ответ

0

Кажется, вы используете тот же текстField2 каждый раз. (Так, в основном вы отпуская его каждый итерации, который должен показать вам последний

вместо:.

_textView2 = [[UITextView alloc] initWithFrame:textRect]; 

попробовать:

UITextView *textView2 = [[UITextView alloc] initWithFrame:textRect];