Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic data in GroupedTableScreen #94

Closed
alagu opened this issue May 25, 2013 · 11 comments
Closed

Dynamic data in GroupedTableScreen #94

alagu opened this issue May 25, 2013 · 11 comments

Comments

@alagu
Copy link

alagu commented May 25, 2013

I'm new to Rubymotion, so this question might be naïve.

I'm using GroupedTableScreen, and I have the table items to be pulled from remote server.

 def on_load
   BW::HTTP.get("http://remoteserver.com/api.json") do |response|
      @games_list = massage_data(response)
   end
 end

 def on_load
    @hometable ||= [{
      title: "List of games",
      cells: @games_list
    },
    {
      title: "Settings",
      cells:
        [{
        title: "Account", action: :account_settings
        },
        {
          title: "Notification", action: :notification_settings  
      }]
    }
  ]
 end

Unfortunately, this doesn't work because BW:HTTP is async. How do I update the cell data in GroupedTable?

@Swatto
Copy link
Contributor

Swatto commented May 25, 2013

Simply add update_table_data after updating your instance variable in the callback.
And you should initialize your instance var before the callback.

def on_load
  @games_list = []

  BW::HTTP.get("http://remoteserver.com/api.json") do |response|
    @games_list = massage_data(response)
    update_table_data
  end

  @hometable ||= [
    {
      title: "List of games",
      cells: @games_list
    },{
      title: "Settings",
      cells:[
        {
          title: "Account", action: :account_settings
        },{
          title: "Notification", action: :notification_settings  
        }
      ]
    }
  ]
end

@alagu
Copy link
Author

alagu commented May 25, 2013

That worked, thanks @Swatto!

@alagu alagu closed this as completed May 25, 2013
@jamonholmgren
Copy link
Owner

Are you actually getting your @games_list cells from the server? That's an interesting way to do it.

@alagu
Copy link
Author

alagu commented May 27, 2013

Yes. I'm getting it from a server. 

Sent from Mobile

On Mon, May 27, 2013 at 11:59 AM, Jamon Holmgren notifications@github.com
wrote:

Are you actually getting your @games_list cells from the server? That's an interesting way to do it.

Reply to this email directly or view it on GitHub:
#94 (comment)

@jamonholmgren
Copy link
Owner

Dynamically programming your app from a server. Sounds vaguely dangerous. :)

@alagu
Copy link
Author

alagu commented May 28, 2013

I show a loading icon when there is a request in progress. I'm also planning to cache it. Can you explain how it could be dangerous?

@jamonholmgren
Copy link
Owner

We allow setting any cell attribute in table_data, so if someone intercepted the request and returned something malicious, it would run. I can't think of anything offhand (hence the "vaguely") but it would be possible to change how your app works pretty easily.

@alagu
Copy link
Author

alagu commented May 28, 2013

Got it. I'm massaging data that comes from the server with few filters. So I guess it should be safe.

@jamonholmgren
Copy link
Owner

That's a good idea. What kind of app are you working on, if I might ask?

@alagu
Copy link
Author

alagu commented May 28, 2013

I'm trying to build a reader to read algorithm problems in Topcoder, for me to read problems, scribble possible solutions(paint), see best submitted solutions. Variable names in above snippets are not real :)

@jamonholmgren
Copy link
Owner

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants