2013-07-18 72 views
0

我在滾動視圖內添加一系列文本視圖滾動視圖。我可以在其滾動視圖中繪製第一個文本視圖。當我嘗試添加第二個文本視圖時,相關的滾動視圖被繪製位,文本視圖不會被添加。任何人都可以指出我在這裏做錯了嗎?在UIScrollView中的UITextView都在另一個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

啊哈!我已經設置了可編輯屬性關閉,但沒有啓用用戶交互。謝謝。 – Barry

+0

注意:scrollEnabled也必須設置爲YES。 – Barry

回答

0

看來你每次都使用相同的textField2。 (所以,基本上你釋放它每次迭代,這應該給你的最後一個

代替:

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

嘗試:

UITextView *textView2 = [[UITextView alloc] initWithFrame:textRect]; 
相關問題