tableView row onEvent issue

Hello Everyone,

First of all, this is my first post, so I’m not sure if I’m making the post on the right place…
I need some help here before I go crazy lol.

My tableView renders just fine, as it should. However, the event handler associated to onEvent is not even getting called.

Here is my code:

[lua]local list = Widget.newTableView
{
left = 0,
top = 10,
–width = 768,
height = 900,
maskFile = “mask.png”
}

–get some stuff from the database (this works fine)
local checkSheets = dbHandler.getCheckSheetTemplates();

– onEvent listener for the tableView
local function onRowTouch( event )

–this line is to test whether the event is getting triggered, but it isn’t
print(“Getting here”);

local row = event.target
local rowGroup = event.view

if event.phase == “press” then
rowGroup.alpha = 0.5;

elseif event.phase == “release” then

print(checkSheets[event.index].LuaFile);
Storyboard.gotoScene(checkSheets[event.index].LuaFile);
end

return true
end

– onRender listener for the tableView
local function onRowRender( event )
local row = event.target
local rowGroup = event.view

local text = display.newRetinaText(checkSheets[event.index].Name, 12, 0, native.SystemFont, 28)
text:setReferencePoint( display.CenterLeftReferencePoint )
text.y = row.height * 0.5
text:setTextColor( 0 )

local bg = display.newRect(0,0, rowGroup.width, rowGroup.height);
bg:setFillColor(230, 230, 230);

– must insert everything into event.view:
rowGroup:insert(bg);
rowGroup:insert( text )
end

for i = 1, #checkSheets do
local rowHeight, rowColor, lineColor;
list:insertRow
{
onEvent=onRowTouch,
onRender=onRowRender,
height=rowHeight,
isCategory=false,
rowColor=rowColor,
lineColor=lineColor,
}
end[/lua]

richard9 already tried it stripping out the dbHandler stuff, and the touch worked for them:

richard9: “I just tried your code (obviously had to strip out all of the dbhandler/checksheets stuff) and I can press a button on rows just fine. Are you getting any error messages in the terminal?”

No richard, there are no errors whatsoever. I also tried it on a device and no luck…

[import]uid: 48579 topic_id: 19020 reply_id: 319020[/import]

Update: I’m using Build 2011.704

Tried on a mac, still nothing. Tried stripping everything out but the code for the list, still nothing, I’m starting to think is something with the build.

Edit: Tried previous builds, and still doesn’t work. Tried the example from the documentation and it does work, so it is not the build. [import]uid: 48579 topic_id: 19020 reply_id: 73325[/import]

I think I found where the problem is, but I’m not sure why is happening.

For some reason, the list is out of phase by 9-10 items (the fist 9-10 do not recognize the touch event. Then the the 10th-11th element receive the touch (index) of the 1st element, and so on. This also holds true for the example in the API, at least on my computer.

Any ideas? [import]uid: 48579 topic_id: 19020 reply_id: 73333[/import]

The first thing I would suggest doing is stripping out all of the SQlite stuff. I did that on my end by:
Step 1. Disabling line 7, 11, 27, 28
Step 2. Editing line 40 to use hardcoded text
Step 3. Line 53 needs to be for the 1,#x bit. I said 1,10
Step 4. (Not really a step. But you’re the only person I’ve ever seen using capital W on widget)

(I think that’s it…)

Doing that I managed to get a wonky tableview on screen. I can click on the entries and get response on the terminal. (Running 703 using iPad skin, OSX)

I know this sounds extreme but can you give that a shot and see what happens? (I always keep a second project folder somewhere specifically for trying out really small code problems…) If it does work, then there is some problem in the SQlite stuff you’re using (or Storyboard, which I have no experience with.) [import]uid: 41884 topic_id: 19020 reply_id: 73338[/import]

Tried all that. Still the same issue, the first few items (1-9 usually) don’t trigger the event. Then, any items after that do trigger the event, but as if they were item (index-9) for example, row 11 will say it is row 2, or something like that. I using iPad skin as well. Thank you [import]uid: 48579 topic_id: 19020 reply_id: 73343[/import]

I tried building a fake table.

local temptable = {} for i = 1, 62 do temptable[i] = "My number is "..i end

…and then used that as the text.

[code] local text = display.newRetinaText(temptable[event.index],12,0,native.SystemFont,28)

– and then also make sure to say for i = 1, #temptable later[/code]

And again, works fine, no offset. Which leads me to believe one of two things. Either:

a. checkSheets is not generating a table with the correct number of rows, or…

b. checkSheets is not generating a table with data in the proper order.

I would strongly suggest doing a for loop print statement after running checkSheets to check the contents you are getting from your SQlite function AND to check the value of #checkSheets, ie:

for i = 1, #checkSheets do print("Name = "..checkSheets[event.index].Name) end print("#checkSheets = "..#checkSheets)

Hope that helps…? [import]uid: 41884 topic_id: 19020 reply_id: 73353[/import]

I really appreciate your help, but it seems there is something else I’m not seeing. I did get rid of all the sql stuff, and created a table with just a loop of fake items:

[lua]_W = display.contentWidth;
_H = display.contentHeight;

local Storyboard = require( “storyboard” )
local Widget = require “widget”;
local scene = Storyboard.newScene();

local function menuPressed(e)
Storyboard.gotoScene(“menu”);
return true;
end

function scene:createScene(event)
local Scene = self.view

–Create the tableView object
local list = Widget.newTableView
{
top = 10,
height = 900,
}

– onEvent listener for the tableView
local function onRowTouch( e )

–this line is to test whether the event is getting triggered, but it isn’t
print(“Getting here”);

local row = e.target
local rowGroup = e.view

print(e.index);
if e.phase == “press” then
rowGroup.alpha = 0.5;
elseif e.phase == “release” then
rowGroup.alpha = 1.0;
end

return true
end

– onRender listener for the tableView
local function onRowRender( event )
local row = event.target
local rowGroup = event.view

local text = display.newRetinaText("Row "… event.index, 12, 0, native.SystemFont, 28)
text:setReferencePoint( display.CenterLeftReferencePoint )
text.y = row.height * 0.5
text:setTextColor( 0 )

local bg = display.newRect(0,0, rowGroup.width, rowGroup.height);
bg:setFillColor(230, 230, 230);

– must insert everything into event.view:
rowGroup:insert(bg);
rowGroup:insert( text )
end

for i = 1, 15 do
local rowHeight, rowColor, lineColor;

list:insertRow
{
onEvent =onRowTouch,
onRender =onRowRender
};
end

local MenuButton = Widget.newButton
{
id = “_menuButton”,
left = 0,
top = _H - 124,
label = “Menu”,
fontSize = 32,
emboss = true,
width = _W,
height = 120,
onRelease = menuPressed
};
Scene:insert(list.view);
Scene:insert(MenuButton.view);
end

function scene:enterScene(event)
local Scene = self.view
end

function scene:exitScene( event )
local Scene = self.view

end

function scene:destroyScene( event )
local Scene = self.view
end
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )

return scene;[/lua]

As you can see there is no sql or anything else, just plain, hardcoded text. I did forgot to mention it was part of a storyboard, but it shouldn’t matter.

I really don’t know where else to look since even the example on the API behaves the same way on my simulator and device. If you were to try the code on this reply, on my simulator/device when you press Row # 11, Row # 2 is the one that highlights (very weird).

Thanks again for all your help. [import]uid: 48579 topic_id: 19020 reply_id: 73364[/import]

Guess what? I tried the code in the main.lua file (not in a storyboard) and it worked like a charm. So I tried it inside the storyboard, but without adding the list.view to the storyboard, and it worked perfectly. It seems to be an issue with adding the table to the storyboard, or to a group. Thanks a lot for your help :slight_smile: [import]uid: 48579 topic_id: 19020 reply_id: 73368[/import]

Good to hear! :slight_smile: [import]uid: 41884 topic_id: 19020 reply_id: 73369[/import]

I had mine partially working in storyboard, but hit an error that I couldn’t get past.

I’m trying to get it working with director. I know my tableView is rendering correctly, but for the life of me I can’t get it to show.

with storyboard the answer was NOT to add it to the “group” displayGroup.

But I tried that with director and I still get a white screen (well I see my two tabbars!).

But director wants everything in localGroup (which doesn’t work either)

Anyone have any idea how I can make this work?

Rob [import]uid: 19626 topic_id: 19020 reply_id: 73440[/import]

Hi Rob,

I’m not sure how to do it with director. However, with storyBoard, my solution was to keep the variable outside the createScene or enterScene, so I could reference it later. DO NOT add the table to the group. Then, write the code to create the table on the “createScene” method. Then, write something like this on the “enterScene” method “myTable.alpha = 1.0”. Then, on the "exitScene method, write this “myTable.alpha = 0.0”. Finally, on the destroyScene, write this “myTable:removeSelf(); myTable = nil;”.
That will make sure you create the table only once, it will hide the table if you change screen, it will show the table if you go back to the same screen without destroying it first, and it will destroy the table if you destroy the screen.

That was my solution, if you find a different one, please let me know. [import]uid: 48579 topic_id: 19020 reply_id: 73443[/import]

I ran into this same issue as was also looking for a workaround. I have tried this weird combo and it seems to work. But it does some weird bounce back stuff. Maybe you could try to see if you it works for you:

[code]
function scene:createScene( event )
local screenGroupBlank = self.view

local screenGroup = display.newGroup()
screenGroup.y = 44
screenGroupBlank:insert( screenGroup )

tableView = widget.newTableView{
width = popx,
height = popy,
maskFile = themask,

}

screenGroup:insert( tableView.view )

–continue on onEvent listener for the tableView and onRender listener for the tableView

end

[/code] [import]uid: 71201 topic_id: 19020 reply_id: 74022[/import]

@rod

Yes, I was having the same issues as you with putting a TableView in storyboard. Some items would receive onEvent and some wouldn’t.

Your solution worked for me about hiding/unhiding the TableView.

I put the widget.newTableView, table options and a table containing the list of items I created above create scene.

In create scene I put the onRowTouch and onRowRender functions. I also put the for loop in create scene.

After that I followed your advice and put the alpha for the table as 1.0 in enter scene and 0.0 in exit scene.

Thanks! [import]uid: 44337 topic_id: 19020 reply_id: 76631[/import]

Interestingly enough… I built for device and it works…

So in the simulator, sometimes I never see my tableView in particular on 2nd view or if a tableView was already showing, but on device it works perfectly… Go Figure.
I’m hoping the next widget update will fix a lot of these.

Now interestingly enough I built a storyboard based app and have had no problems with tableViews. I still don’t put them into groups and manually remove them during the exitScene phase.

I think the trick is:

createScene: create a background display object and insert it into “group”
enterScene: create the tableView, do not insert.
exitScene: remove the tableView
destroyScene: no extra processing.

This seems to work in the simulator as well as it works on device.
[import]uid: 19626 topic_id: 19020 reply_id: 76674[/import]