Page 1 of 1

ScrollLineIntoView not working on iOS Simulator

Posted: Mon Sep 20, 2021 4:01 pm
by Bellballer1
Hello,

My app has a data grid with 50 rows. When a user taps one of the rows in the data grid, it opens another card where an image is displayed. When the user goes back to the card with the data grid, I want that card to open with the row that was just tapped, in view. For example, if the user taps on row 39 of the data grid, after viewing the image on the next card, I want row 39 to be in view when the comes back to the card with the data grid.

I am able to do this on the desktop version of LiveCode where I am building the app, however, when I test it on the iOS Simulator and my iPhone, when the card with the data grid is re-opened, the top rows of the data grid are displayed.

This is the code in the card script of the card that has the data grid:

Code: Select all

local gHilitedLine, pLine

on preOpenCard
 put the dgHilitedLine of group "DataGrid 1" into gHilitedLine
 
 put gHilitedLine into pLine
  
goToIndexedLine pLine

 end preOpenCard
 
 command goToIndexedLine pLine
   dispatch "ScrollLineIntoView" to group "DataGrid 1" with pLine
   set the dgHilitedLines of group "DataGrid 1" to pLine
end goToIndexedLine
 
I found "ScrollLineIntoView" in the dictionary because even when I had "set the dgHilitedLines of group "DataGrid 1" to gHilitedLine", it highlights the correct line, but it goes to the top of the data grid when the card is re-opened (in the simulator or iPhone).

Again, this code works perfectly fine on the desktop version of LiveCode where I'm building the app, but it doesn't work on the simulator or actual phone (e.g. if I tap row 39 on the simulator or the iPhone, when the card with the data grid is re-opened, it takes me to the top of the data grid, not lower where I can view row 39). Any thoughts?

Thanks,
Bellballer1

Re: ScrollLineIntoView not working on iOS Simulator

Posted: Tue Sep 21, 2021 4:38 pm
by jacque
I think the first thing I'd do is to see if the dgHilitedLine has changed when returning to the card. Add an answer command temporarily to check:

Code: Select all

put the dgHilitedLine of group "DataGrid 1" into gHilitedLine
answer "Hilitedline:" && gHilitedLine -- add this 
Also, I don't see a need to have two local script variables with the same content, but that's a different thing.

Re: ScrollLineIntoView not working on iOS Simulator

Posted: Tue Sep 21, 2021 5:06 pm
by Bellballer1
Hi Jacque,

Thanks for the response.

The dgHilitedLine has not changed when returning to the card. The answer command that you suggested, proves that.

I only have an issue when I test on the iOS simulator and on my iPhone. I'm trying to figure out why the data grid returns to the top of the card on the simulator and iPhone, but works as it should on the desktop/build version. Thanks.

Re: ScrollLineIntoView not working on iOS Simulator

Posted: Thu Sep 23, 2021 2:56 am
by Bellballer1
I solved the problem I was having. The card needs to be open first. As I found in the LiveCode Lessons under Data Grids--"What sorts of things should I not do in order to avoid needless suffering?":

"When a Data Grid renders it dynamically creates fields and accesses certain properties. Some of these properties can not be properly reported by the Revolution engine unless the field is on an open card."

I knew there had to be a simple explanation as to why the data grid wasn't performing on the simulator and phone.

Bellballer1

Re: ScrollLineIntoView not working on iOS Simulator

Posted: Thu Sep 23, 2021 6:45 am
by jacque
That's interesting, you'd think it would fail in the IDE too. But I'm glad you were able to solve it. So did you move the commands to the openCard handler?

Re: ScrollLineIntoView not working on iOS Simulator

Posted: Thu Sep 23, 2021 2:15 pm
by Bellballer1
Hi Jacque,

I did move the commands to the openCard handler. The fact that it was not failing in the IDE contributed to my "needless suffering."