Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Lua Wax UITableViewController UITableViewDataSource UITableViewDelegate implementation problem - Gideros Forum

Lua Wax UITableViewController UITableViewDataSource UITableViewDelegate implementation problem

omeromer Member
edited February 2013 in Plugins
Hello,
Whenever we used uikit.mm
local tableView = TableView.new("Plain")
is enough to implement any idea.
Lua Wax good but I can not find any table based solution that runs on Gideros.
We must implement an data source UITableViewController,"UITableViewDataSource","UITableViewDelegate"
I checked Wax samples on repo. They are old. They are not running on gideros platform.
Do you have any fresh solution, code sample to use on wax gideros platform?
Thanks,
Tagged:

Comments

  • SimpleLoopSimpleLoop Member
    Accepted Answer
    Here is an example I just made.
    Make sure you are running it on a device or in the iOS Simulator using the Gideros Player App with the wax plugin installed.
    I have just tested it and it works fine for me so if it doesn't run on yours I would check your Gideros Player App has the wax plugin installed in it correctly :).

    Regards,
    Giles

    Likes: omer

    zip
    zip
    TableViews.zip
    11K
    +1 -1 (+1 / -0 ) Share on Facebook
  • omeromer Member
    edited February 2013
    Thanks for kindly answer, I am hacking your code at moment. I am checking limits or alternatives to use most efficient Apple physiology using wax and Lua. I'm glad to see some friends are checking wax option for Lua and Gideros. I am testing your code to export selecting element to use outer modules or calling modules. Yes, I can do it using global variables. But I want to bind it using wax messaging system, preferably binding delegate variables. For example, I wanted to change scene using table row selection and I wrote an simple code. I used Andy BhWaxDemo.lua example. But it is not working.
    waxClass{"vTableDelegate",  protocols = { "UITableViewDelegate"}}
     
    function tableView_didSelectRowAtIndexPath(self, tableView, indexPath)
    	--If a row is selected, deselect it
    	self.tableView:deselectRowAtIndexPath_animated(indexPath, true)
    	if self.tableView_didSelectRowAtIndexPathHandler then
    		self.tableView_didSelectRowAtIndexPathHandler(self.handlerTarget, indexPath)
    	end
    end
     
    waxClass{"viewWithTable", UIViewController, protocols = {"UITableViewDataSource"}}
    ...
    function viewDidLoad(self)
    	--set items to show in table
    	items = {"one", "two", "three"}
     
    	--set view color to white
    	self:view():setBackgroundColor(UIColor:whiteColor())
     
    	--create the table
    	self.tableView = UITableView:initWithFrame_style(CGRect(0,0,320,480),UITableViewStylePlain)
    	--set its background color
    	self.tableView:setBackgroundColor(UIColor:clearColor())
    	--self.tableView:setBackgroundColor(UIColor:lightGrayColor())
    	--set the data source to this view
    	self.tableView:setDataSource(self)
    	--set the delegate to this view
    	local delegate=vTableDelegate:init() --vTableDelegate
    	delegate.handlerTarget=self
    	delegate.tableView_didSelectRowAtIndexPathHandler=self.ChangeScene
    	self.handlerTarget=self
    	self.tableView_didSelectRowAtIndexPathHandler=self.ChangeScene
    	self.tableView:setDelegate(delegate) --self)
    	--add it to the view
    	self:view():addSubview(self.tableView)
    end
    ...
  • I've been able to get a working UITableViewController using similar code to @SimpleLoop, however, when I try and load it inside a SceneManager scene I hit issues where scrolling the table view either crashes my app or the data just disappears.

    Does anyone have any ideas on why that would happen?
    [ Twitter: pushpoke | Facebook: facebook.com/pushpoke | Web: pushpoke.com | Letter Stack iOS: letterstack.com ]
  • Just as I write that, I manage to get it to work. The problem was I had:
    -- Scene GameTable
    gametable = gideros.class(Sprite)
    function gametable:init()
    	-- display view
    	local tableView = PPTableViewController:init()
    	getRootViewController():view():addSubview(tableView:view())
    end
    but needed to make the tableView a global instead of local.
    -- Scene GameTable
    gametable = gideros.class(Sprite)
    function gametable:init()
    	-- display view
    	self.tableView = PPTableViewController:init()
    	getRootViewController():view():addSubview(self.tableView:view())
    end
    [ Twitter: pushpoke | Facebook: facebook.com/pushpoke | Web: pushpoke.com | Letter Stack iOS: letterstack.com ]
  • Issue now is that I can't seem to remove the view when I transition to another scene.
    I tried doing:
    function gametable:onExitBegin()
    	self.tableView:view():removeFromSuperview()
    end
    But it doesn't actually remove it. Then if I make any contact with the table after that, it crashes.

    I've also noticed performance is really bad when you're scrolling the table up and down. My FPS drops from 60 to 8-12 and my background music cuts in and out.
    [ Twitter: pushpoke | Facebook: facebook.com/pushpoke | Web: pushpoke.com | Letter Stack iOS: letterstack.com ]
  • I managed to fix the removal of it (I was missed the onExitBegin() eventListener), but the performance is still REALLY bad, to the point where it is unusable.

    Basically, it seems that anything under the table view is given really low priority. I have background music and an emitter on the stage. If I make the tableview transparent then I can see the emitter stopping and hear the music stop whenever I start dragging the table. As soon as I stop dragging they move again.

    @bowerandy, any ideas?
    [ Twitter: pushpoke | Facebook: facebook.com/pushpoke | Web: pushpoke.com | Letter Stack iOS: letterstack.com ]
  • @omer - I have table row selection triggering a scene change by doing the following:

    I pass in an EventDispatcher to the tableview on init, then when a table row is selected I fire off an event with the rowId. Then you listen for that event in your scene and change scenes as necessary.

    <span class="co1">-- init function</span>
    <span class="kw1">function</span> PPTableViewController:init<span class="br0">&#40;</span>dispatcher<span class="br0">&#41;</span>
    	self.super:init<span class="br0">&#40;</span><span class="br0">&#41;</span>
    	self.dispatcher <span class="sy0">=</span> dispatcher
    	<span class="kw1">return</span> self
    <span class="kw1">end</span>
    &nbsp;
    ...
    &nbsp;
    <span class="kw1">function</span> PPTableViewController:tableView_didSelectRowAtIndexPath<span class="br0">&#40;</span>self, indexPath<span class="br0">&#41;</span>
    	self:deselectRowAtIndexPath_animated<span class="br0">&#40;</span>indexPath, <span class="kw1">true</span><span class="br0">&#41;</span>
    	<span class="kw1">local</span> completeEvent <span class="sy0">=</span> Event.new<span class="br0">&#40;</span><span class="st0">"chooseItem"</span><span class="br0">&#41;</span>
    	completeEvent.rowId <span class="sy0">=</span> indexPath:row<span class="br0">&#40;</span><span class="br0">&#41;</span>
    	self:delegate<span class="br0">&#40;</span><span class="br0">&#41;</span>.dispatcher:dispatchEvent<span class="br0">&#40;</span>completeEvent<span class="br0">&#41;</span>
    <span class="kw1">end</span>
    &nbsp;
    <span class="co1">-- your scene class</span>
    yourscene <span class="sy0">=</span> gideros.class<span class="br0">&#40;</span>Sprite<span class="br0">&#41;</span>
    &nbsp;
    <span class="kw1">function</span> yourscene:init<span class="br0">&#40;</span><span class="br0">&#41;</span>
    	self.dispatcher <span class="sy0">=</span> EventDispatcher.new<span class="br0">&#40;</span><span class="br0">&#41;</span>
    	self.tableView <span class="sy0">=</span> PPTableViewController:init<span class="br0">&#40;</span>self.dispatcher<span class="br0">&#41;</span>
    	getRootViewController<span class="br0">&#40;</span><span class="br0">&#41;</span>:view<span class="br0">&#40;</span><span class="br0">&#41;</span>:addSubview<span class="br0">&#40;</span>self.tableView:view<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
    &nbsp;
    	self:addEventListener<span class="br0">&#40;</span><span class="st0">"exitBegin"</span>, self.onExitBegin, self<span class="br0">&#41;</span>
    	self.dispatcher:addEventListener<span class="br0">&#40;</span><span class="st0">"chooseItem"</span>, self.onItemSelection, self<span class="br0">&#41;</span>
    <span class="kw1">end</span>
    &nbsp;
    <span class="kw1">function</span> yourscene:onItemSelection<span class="br0">&#40;</span>event<span class="br0">&#41;</span>
    	<span class="kw1">print</span><span class="br0">&#40;</span><span class="st0">"ITEM SELECTED"</span> .. event.rowId<span class="br0">&#41;</span>
    	<span class="co1">-- determine scene and change</span>
    	sceneManager:changeScene<span class="br0">&#40;</span><span class="st0">"start"</span>, <span class="nu0">1</span>, sceneManager.fade, conf.easing<span class="br0">&#41;</span>
    <span class="kw1">end</span>
    &nbsp;
    <span class="kw1">function</span> yourscene:onExitBegin<span class="br0">&#40;</span><span class="br0">&#41;</span>
    	<span class="co1">-- remove tableview</span>
    	self.tableView:view<span class="br0">&#40;</span><span class="br0">&#41;</span>:removeFromSuperview<span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="kw1">end</span>
    [ Twitter: pushpoke | Facebook: facebook.com/pushpoke | Web: pushpoke.com | Letter Stack iOS: letterstack.com ]
  • bowerandybowerandy Guru
    edited March 2013
    @krisis, first of all, have you taken a look at BhUIViewFrame as a way of managing UIViews alongside the Gideros SceneManager (as well as allowing them to be tweened/wrapped by physics etc).

    http://www.giderosmobile.com/forum/discussion/comment/13793#Comment_13793

    There's also another example video below; the code is part of the Hot wax demo program that you downloaded from GitHub:



    Aside from that, I'm not really sure what might be causing your performance problems. You should be aware that calls into and out of wax are quite slow, especially the marshalling of the parameters between the two spaces. I'm not sure exactly but you wouldn't want to be doing too many of these calls inside an ENTER_FRAME handler at 60fps, for example. The above video shows that you can make a reasonable number of Wax calls and maintain a decent framerate though.

    If you have a callback from your table controller into Lua that is being called each time the table is scrolled, you could try disabling that to see if it the frequency of that particular callback that is causing the issue.

    Bear in mind that the Hot Wax stuff isn't really intended as a way of being able to code and entire Objective-C style app in Lua. It would most likely be too slow for that.

    best regards
  • Hey @bowerandy,

    The performance of the UITableViewController itself is perfectly fine and scrolling is great, but it doesn't seem to interact well with other parts of Gideros that are in the view behind it (or on the stage). As mentioned, music and moving parts in the view behind the table screech to a halt.

    I don't have any callbacks on scroll, that part is all just handled by Obj-C. The only callbacks I have are on row selection to dismiss the table. I also don't have anything wax related in an ENTER_FRAME handler. It is really just a basic UITableViewController on a fairly basic scene.

    I've looked at the BhUIViewFrame code, and mine isn't all that different. I'll try code it up more closely to what you've got and see if it makes any difference.
    [ Twitter: pushpoke | Facebook: facebook.com/pushpoke | Web: pushpoke.com | Letter Stack iOS: letterstack.com ]
  • bowerandybowerandy Guru
    edited March 2013
    @krisis, I have just noticed a similar slow-down issue when bringing up an IOS image picker on top of a Gideros scene and then scrolling the contents up and down.

    The frame rate drops from 60FPS to something below 20FPS. There are also no callbacks into the code so I guess it is just that the scrolling is being handled at a very high priority (presumably in Apple's quest for maximum UI smoothness). I just found this:

    http://www.phonearena.com/news/Here-is-why-Android-is-laggy-and-why-its-going-to-remain-like-that-in-the-near-future_id24434.

    In particular: "the core reason why Android is laggy is the way it treats UI rendering. While on iOS UI rendering happens in a separate thread with **real-time** priority, on Android this happens in the main thread with normal priority" (my emphasis).

    I doubt there's much we can do about it at our end.

    best regards
Sign In or Register to comment.