iOS Question SelectionStart behaviour

Markos

Active Member
Licensed User
Longtime User
Hi All,

I was hoping Selectionstart in textview would behave like in edittext in b4a and position the cursor at the end of the string with with code 'textview1.selectionstart = textview1.text.length' and in a multiline scenario the cursor would scroll down the textview to the last character row.

I'm not getting that effect. Can you please confirm this is how the result will be for this enhanced method/property.

Thanks

Mark
 

Markos

Active Member
Licensed User
Longtime User
Hi All,

I was hoping Selectionstart in textview would behave like in edittext in b4a and position the cursor at the end of the string with with code 'textview1.selectionstart = textview1.text.length' and in a multiline scenario the cursor would scroll down the textview to the last character row.

I'm not getting that effect. Can you please confirm this is how the result will be for this enhanced method/property.

Thanks

Mark

I have used scrollto and it works but it scrolls from the top. Can it do an incremental scroll from a different row or index. The reason being I want to fill the textview line by line and when current window is full to scroll up etc
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
It does but is there a way to have it scroll from current position to the desired index rather than always scroll from index 0 to the desired index
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Hi Erel

Perhaps a new method scrollto2 that moves to the desired index without animation so we get the nextline effect similar to b4a setting selectionstart = stringlength
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

try the following method:

B4X:
Sub ScrollTo2(TV As TextView,Index As Int)
    Dim NaObj As NativeObject = Me
    NaObj.RunMethod("Scroll::",Array(TV,Index))
    #If Objc
        -(void)Scroll:(UITextView*)TV :(int)Index{
            [UIView setAnimationsEnabled:NO];
            [TV scrollRangeToVisible:NSMakeRange(Index,0)];
            [UIView setAnimationsEnabled:YES];
        }
    #End if
End Sub

Jan
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
I prefer to use NativeObject if possible:
B4X:
Dim no As NativeObject
no.Initialize("UIView").RunMethod("setAnimationEnabled:", Array(False))
tv.ScrollTo(index)
no.RunMethod("setAnimationEnabled:", Array(True))
Thank you both.

The results are as follows:
JanPro
-------
Compiles fine and runs without animation however the scrolling stops after I append the 4th string to the textview. Its like the scroll resets goes back to index=0 even if I tell it to scroll to the end. Btw this is the same behaviour even without the animation being disabled, has to be a bug of sorts.

Erel
----
Compiles fine. No text appears in the textview when I implement the setanimatioenabled using your code.

How can I compensate for this ebhaviour and secondly I would like to get Erel's code working as it seems straight forward but the results are unexpected.

Thanks

Mark
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Thank you both.

The results are as follows:
JanPro
-------
Compiles fine and runs without animation however the scrolling stops after I append the 4th string to the textview. Its like the scroll resets goes back to index=0 even if I tell it to scroll to the end. Btw this is the same behaviour even without the animation being disabled, has to be a bug of sorts.

Erel
----
Compiles fine. No text appears in the textview when I implement the setanimatioenabled using your code.

How can I compensate for this ebhaviour and secondly I would like to get Erel's code working as it seems straight forward but the results are unexpected.

Thanks

Mark
Oh I forgot to mention. The scrolling only starts if I click on the textview scroll it up manually only then the scrolling executes properly, but again after a few appends to the textview it goes back to no scroll then I have to click on the textview manually scroll up and then it starts up again altho briefly.
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Hi Erel

is index in Scrollto(index) the index of a row or the index of a character in the textview. I'm assuming the latter
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
It is the index of a character. Note that I haven't test the code I posted. It was just a conversion of the inline objc code posted by JanPro.

Please create a small example that demonstrates the problem and upload it.

Thanks for the help Erel. Please find attached a quickie example of adding text to a textview and using the original scrollto to get the textview content to scroll down to that last line.

The issues are as follows:
1) To remove the animation in moving to lastline
2) To ensure the scrolling fires as it should
3) I don't have to manually scroll down the textview for the initial scroll to take effect
 

Attachments

  • tvsample.zip
    2.3 KB · Views: 204
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Thanks for the help Erel. Please find attached a quickie example of adding text to a textview and using the original scrollto to get the textview content to scroll down to that last line.

The issues are as follows:
1) To remove the animation in moving to lastline
2) To ensure the scrolling fires as it should
3) I don't have to manually scroll down the textview for the initial scroll to take effect
Oh All this is of course after enough text is added to fill the textview and the rows must scroll up to see the new text. Hence why obviously I want to scroll to last indexed character in the textview. If this doesnt work I welcome an alternative method to try...

Thanx
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Ok will do in my next post and just as fyi I produced the layout via code and the layout only has the Activity object to cater for variants so it should work nicely to illustrate my intent for textview s rolling up line by line
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tested it again. Still the layout file is missing. However it doesn't really matter.

Note that this is not the correct code to implement a flexible layout. You should instead use the designer and set the anchors.

About the scrolling, I don't see any problem. It scrolls nicely whenever I click on the Add button.
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
I knew the flexible layout I would have to revisit. I cheated by coding the views rather than using the designer to fast track porting to iOS. I will have some questions on that soon enough.

On the scrolling how come it works for you and not me. Could there be a version of android sdk or something about minimum iOS version for it to function properly?
 
Upvote 0
Top