NSTextView stops being able to scroll once new text is set - ios

I have a TextView made in the Interface Builder;
It scrolls fine with its default text, but as soon as I programatically set the text to something else, it no longer scrolls.
I do not disable scrolling, and I have tried enabling scrolling (setScrollEnabled:YES), and user interaction (setUserInteractionEnabled:YES) both of which make no difference.
The things that I have found:
It scrolls with the default text showing
It doesn't seem to matter what text I set in it, it just stops scrolling as soon as it is set. I'm doing it programatically like this:
self.myTextView.text = #"any text"; (or [self.myTextView setText:#"any text"]; has the same effect.)
I have two other Textfield in the same View, one of which is using the View Controller as its delegate. The TextField in question is not using the View Controller as its delegate. None of the delegate methods set anything to do with scrolling.
Both of the other TextViews have their scrolling capability set to defaults. If I change the one that doesn't need it to no scrolling, it makes no difference to the problem.
The one that has the View Controller as its delegate continues to scroll after I edit it (non programatically) and this one continues to be able to scroll once the one in question freezes.
If I delete these two other TextFields, then the one in question works as expected, i.e. it scrolls after adding text.
Any thoughts?
Thanks.

Make sure your new text is long enough to be able to get scroll.
if text is just one line it wont scroll but if its larger then text area size then it will scroll its by default settings

Related

How to move my chat input bar up on top with keyboard in Xcode?

I create a chat program. I've created my chat sequence using TableView. Now I have a view on the bottom of the page, contains one TextField and a send button. Now if I press on the TextField, the keyboard appears. I need to:
reduce the height of the tableView so that I still can see the most recent chat message, and return it to its former height if the keyboard is hidden.
move the view up to sit on top of the keyboard, and return it to its former position if the keyboard is hidden.
do both of things above with animation.
I'm still newbie in this keyboard + animation area. I only know I will need to implement textFieldDidBeginEditing and textFieldDidEndEditing to do this. But I don't know what code I should implement inside it. This answer provided some, but not the exact answer to my problem (it only moves the floating TextField in the scrollable view of TableView to be within the visible area, not moving a view not related with TableView). Any help or even article will be appreciated. Thanks!

UITableView setContentOffset: called from main loop?

I have a UITableView with a variable size UITextView and when the user is about to enter text I move the text field up so it is visible above the keyboard. All is good. But when I adjust the contentOffset while the user is typing it works fine too, but a moment later the table view automatically scrolls back to the top, hiding the text view behind the keyboard. As it turns out, setContentOffset is for some reason called from the main loop with the initial value again. This is really ruining my day, it works all fine and then the system seems to decide to mess up my work again deliberately.
Why is this so? How can I prevent this?
Here is a screenshot of the stack trace:

iOS UITextView content offset and bounds origion change after changing text programmatically

I have a UITextView. The text in the view keeps changing based on user action. On many occasions, the text is too large to fit and so my text view (which has a desired fixed width and height) scrolls the text. The control flow is something like this
1) user takes some action, and text view appears with some text (possibly more than what can fit, so comes with a scroll)
2) user dismisses the view (I simply hide the text view)
3) user takes another action, and text view appears with new text (i use UITextView setText to reassign the text, and simply turn the hidden property to NO)
My text cannot be edited by the user. It is always reset to a different string in code
Problem:
When the textview is redrawn/rendered with the new text, on some occassions the contentoffset.y AND bounds.origin.y values of the text view are set to something besides 0, which is not desirable. It is intermittent, but creates a major UI issue. At least I think those new values are what causes the UI to look so weird. Open to other suggestions here...
I want to know why this happens, and how to fix this? Since the text is changed programatically, I can't depend on textViewDidChange: to reset these values.
EDIT: This is how I am changingt he text everytime something new has to be placed in the textview
[textView1 setText:someNSString];
where someNSString is, well, some string with text

Scroll back to top in iOS UITextView after change of text

I have a UITextView. The text in the view keeps changing based on user action. On many occasions, the text is too large to fit and so my text view (which has a desired fixed width and height) scrolls the text. The control flow is something like this
1) user takes some action, and text view appears with some text (possibly more than what can fit, so comes with a scroll)
2) user dismisses the view (I simply hide the text view)
3) user another action, and text view appears with new text (i use UITextView setText to reassign the text, and simply turn the hidden property to NO)
Problem Scenario:
Perform step 1 above, user scroll down a little to read the content, then proceeds with step 2 and 3. But when the text view reappears, the view is still scrolled a little from the last interaction. I want the text to be visible from the start, meaning, the scroll shud be "reset"
What I tried:
[textView scrollRangeToVisible:NSMakeRange(0,0)]; //OR
[textView scrollRangeToVisible:NSMakeRange(0,600)]; //600 being an approximate number of characters that can show in my text view after which they flow out and it has to be scrolled.
this was the most successful attempt. Worked most of the time, except, sometimes, intermittently, there would be a lot of extra space on top of my line 1 of the text, like someone scrolled/swiped it down and froze it there.
PS:My text cannot be edited by the user. It is always reset to a different string in code

iOS: Stop ScrollView from making room when selecting textfield at top

I've scoured through several questions asking about how to prevent scrolling when selecting a first responder however nothing I find seems to work for this issue.
I have a UITextField above my table view at the very top of my page. When the user selects it (or when I do it programmatically) it drops down a bit, seemingly giving room for options such as "paste" or autocorrect (which I've disabled). I'd like to prevent this from happening.
I've tried setting the scroll position myself, which it initially does, but then it instantly jumps down a bit. Is there a way I can make the paste/edit bubble appear below the textfield (like it does with textfields in the header)? I'm thinking perhaps that will prevent it from jumping downwards, but I can't find information on this.
I'm completely stuck so any help is appreciated. Links, vague suggestions, whatever. Thank you.
Try embedding your text field in a scroll view the same size as your text field.
The reason why this should work is because when a text field becomes first responder, it only scrolls the scroll view that is its most recent ancestor in the view hierarchy. If it only finds the dummy scroll view, whose content size should not exceed its bounds size, then no scrolling should occur in either scroll view.

Resources