views:

129

answers:

2

Hi,

I have a UITextView included in a UITableViewCell. The layout is correct when the views are initially displayed, but once I click in the UITextView it DOES NOT automatically scrolls up and the whole UITextView becomes invisible.

This image is when the UITextView is not active:

http://img13.imageshack.us/img13/3894/unloaded.png

And this one is when I clicked in the UITextView to make it active:

img337.imageshack.us/img337/2583/loaded.png (Put "http://" before the link, I can't post more than one Hyperlink)

I want the cell with the UITextView to scroll up. How can I achieve this?

Any suggestions are appreciated.

Julio Cezar

A: 

The simplest way would be to make an IBOutlet for the items you want to move up, and then in the code do something like this when your text field is selected:

myTextView.center.y = 200 or whatever y value you see fit.

SeniorShizzle
Thanks for the answer but it did not work. The only thing that happens is that my UITextView goes outside the cell.
jcdmb
If the cell and UIView are separate then you have to move them both up, or if they are both of the same view then you can move them together.
SeniorShizzle
It is not a dynamic solution. It would work for one case only, but I generate my view dynamically from a XML File. Would appreciate any other suggestion.
jcdmb
I'd love to help but Im more into the basics, no XML for me :(
SeniorShizzle
Hi SeniorShizzle, I've already done it. I've just posted my answer in the thread. Thanks anyway for helping!
jcdmb
A: 

I've already done it. My solution is not the best but it works very well: everything happens on tableView:cellForRowAtIndexPath:

1) For every cell that has a UITextView I have a NSDictionary: I save all my UITextView's on the cells on NSDictionary with a particular key.

2) And I also have another NSDictionary with the indexPath objects that are created in tableView:cellForRowAtIndexPath. If a cell A has UITextView A, they will have the same key in the NSDictionaries.

3) I implement the UITextViewDelegate and call textViewDidBeginEditing: here is my code:

  • (void)textFieldDidBeginEditing: (UITextField *)textField {

NSArray *keys = [self.answersDic allKeysForObject:textField];

id *key = (id *)[keys objectAtIndex:0];

NSIndexPath *tempIndex=[self.indexPathForViews objectForKey:key];

[tableViewLocal scrollToRowAtIndexPath:tempIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];

}

OBSERVATIONS:

a) answersDic is the NSDictionary where my UITextViews are saved.

b) indexPathForViews is the NSDictionary where my IndexPaths are saved.

c) the most important part of this code: the method, that brings the view to scroll up:

[tableViewLocal scrollToRowAtIndexPath:tempIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];

So, thats it. Thanks for your help!

jcdmb