infinitered / redpotion

We believe iPhone development should be clean, scalable, and fast with a language that developers not only enjoy, but actively choose. With the advent of Ruby for iPhone development the RubyMotion community has combined and tested the most active and powerful gems into a single package called RedPotion
MIT License
235 stars 41 forks source link

Idea: "headless" tables #65

Open jamonholmgren opened 9 years ago

jamonholmgren commented 9 years ago

@twerth and I discussed several scenarios related to #63 and https://github.com/infinitered/rmq/issues/232. One of the sticking points is collections or sets of data and how to represent those on a screen. Todd and I agree that tables are underutilized as child views, and I'd like to make that easier.

I have this concept of a "headless" table view. ProMotion makes it easy to make a PM::TableScreen subclass, but what if we could do this in a normal screen:

class ContactScreen < PM::Screen
  def on_load
    append email_view, :emails
  end

  def email_view
    @email_view ||= build_table_view([{
      title: "Email addresses",
      cells: @emails.map do |email|
        {
          cell_class: SomeCustomClass,
          title: email,
          action: :tapped_email,
          arguments: { email: email } 
        }
      end
    }])
  end

  def tapped_email(args={})
    args[:email] # => some email
  end
end

No explicit PM::TableScreen subclass would be necessary. All events would be passed through to the parent screen, and the UITableViewController instance would be automatically built, added as a childViewController, and managed from your current screen instance. These things are usually pretty boilerplate anyway, so it makes sense to have a helper for this.

Thoughts?

jamonholmgren commented 9 years ago

It's possible that this should be considered as a ProMotion-proper feature, so I've added an issue there too to track this. https://github.com/clearsightstudio/ProMotion/issues/652