How can I add a row to an existing tableView by clicking on a button?

Hi there,

I’ve got a question that is driving me crazy for some time now. Let’s say I have split a (storyboard-)screen into two parts - I have three buttons on the left while there is the tableView-object on the right. The tableView is prefilled with some data/rows and clicking on the buttons shall add a new row to the table, but I somehow cannot figure out, how to do that really (and only get errors).

So can someone help and tell me, how I can manage that?

Thanks in advance,

Patrick

After your tableView has been created you could simple do something like this:

[lua]

local function newtablerow()
        local isCategory = false
        local rowHeight = 40
        local rowColor =
        {
            default = { 255, 255, 255 },
        }
        local lineColor = { 204, 204, 204 }
        – Insert the row into the tableView
        tableView:insertRow
        {
            isCategory = isCategory,
            rowHeight = rowHeight,
            rowColor = rowColor,
            lineColor = lineColor,
        }

end

local function addrow(event)

     if event.phase == “ended” then

         newtablerow()

     end

end

– button code

– add button event listener which calls addrow

[/lua]

Assuming you have an onRowRender function you can populate the new row.  To add more than 1 row just put the creation of a new row in a for loop.

Hope this helps

Thanks a lot Icy Spark!

Now it works fine :slight_smile:

After your tableView has been created you could simple do something like this:

[lua]

local function newtablerow()
        local isCategory = false
        local rowHeight = 40
        local rowColor =
        {
            default = { 255, 255, 255 },
        }
        local lineColor = { 204, 204, 204 }
        – Insert the row into the tableView
        tableView:insertRow
        {
            isCategory = isCategory,
            rowHeight = rowHeight,
            rowColor = rowColor,
            lineColor = lineColor,
        }

end

local function addrow(event)

     if event.phase == “ended” then

         newtablerow()

     end

end

– button code

– add button event listener which calls addrow

[/lua]

Assuming you have an onRowRender function you can populate the new row.  To add more than 1 row just put the creation of a new row in a for loop.

Hope this helps

Thanks a lot Icy Spark!

Now it works fine :slight_smile: