0

i have 2 textview in a viewcontroller. the 1st textview is not editable, but the 2nd is editable. i want to make both of them scroll in the same position and size when the keyboard is appear. I think i have to use UIScrollView as base of both of textview. And then i add the UIScrollView in xib (bot of textview are made in xib too). and this is the picture if this hierarchy :

alt text

in the viewDidLoad method, i add this code :

- (void)viewDidLoad {
[super viewDidLoad];

[scrollTextView addSubview:lineNumberTextView];
[scrollTextView addSubview:_codeTextView];

[lineNumberTextView bringSubviewToFront:scrollTextView];
[_codeTextView bringSubviewToFront:scrollTextView];

}

but after that i can't scroll anything. What i have to do? thx for the advices

UPDATE

this my code after do some advises like mac gave to me :

- (void)viewDidLoad {
[super viewDidLoad];

scrollTextView.showsVerticalScrollIndicator = YES;
scrollTextView.showsHorizontalScrollIndicator = YES;
scrollTextView.scrollEnabled = YES;

_codeTextView.showsHorizontalScrollIndicator = NO;
_codeTextView.showsVerticalScrollIndicator = NO;
_codeTextView.scrollEnabled = YES;
_codeTextView.tag = 0;
_codeTextView.delegate = self;

lineNumberTextView.showsVerticalScrollIndicator = NO;
lineNumberTextView.showsHorizontalScrollIndicator = NO;
lineNumberTextView.scrollEnabled = YES;
lineNumberTextView.tag = 1;
lineNumberTextView.delegate = self;

}

but just the _codeTextView scroll, the lineTextVew stil didn't scroll...somebody know why??

R. Dewi
  • 4,141
  • 9
  • 41
  • 66

2 Answers2

0

Verify that user interaction enabled is checked in interface builder for the 2nd textview.

jamihash
  • 1,900
  • 1
  • 12
  • 15
  • how if i want to made the 1st textview not editable and the 2nd textview editable? is there any advice? – R. Dewi Dec 27 '10 at 04:00
  • i try to use Embed Object In from the xib, like example on this page http://stackoverflow.com/questions/1521308/how-to-add-uiscrollview-to-interface-builder, but the "Embed Object In" in my xib can not selected, do you know why? – R. Dewi Dec 27 '10 at 04:09
0

you give some tag values for both the textfields, and in the delegate methods, do userinteraction enabled(false,true)whatever you required.

mac
  • 4,760
  • 7
  • 31
  • 33
  • i have to do like that...give a tag to every textview, and set the userinteractionenabled:YES to both off them. but just the 2nd that scroll, the 1st is still didn't scroll – R. Dewi Dec 27 '10 at 08:58