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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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

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.

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?

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.)

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

I tried building a fake table.

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

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
_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;

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 :)

Good to hear! :)

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

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.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

@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!

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.

views:3419 update:2012/1/3 13:02:13
corona forums © 2003-2011