jamonholmgren / ProMotion

ProMotion is a RubyMotion gem that makes iPhone development less like Objective-C and more like Ruby.
MIT License
1.26k stars 147 forks source link

TableScreen and Teacup #338

Closed stefanvermaas closed 10 years ago

stefanvermaas commented 10 years ago

Hi @jamonholmgren,

I found myself struggling with integrating a custom TableScreen and Teacup into ProMotion. I want to create a view with a subview. That subview must be the PM::TableScreen view.

But I'm not sure how to continue, because how can I use TableScreen from here? How should I alter the UITableView? This is what I thought what was right, but apparently I wasn't :)

# appointments.rb
content = subview(UIView, :appointment_content) do
   appointment_list = subview(UITableView, delegate: self)
end

# appointments_list.rb
class AppointmentsListScreen < PM::TableScreen
end

Any ideas?

Cheers.

jamonholmgren commented 10 years ago

Hi @stefanvermaas ,

So the recommended way to use a UITableView as a subview is using two Screens and adding the TableScreen's view as a subview of the wrapper screen's view. It sounds weird, but that's actually Apple's official way of doing it.

So, here's some basic code.

# appointments.rb
class Appointments < PM::Screen
  def on_load
    @appointment_list_screen = AppointmentsListScreen.new
    self.addChildViewController @appointment_list_screen
    content = subview(UIView, :appointment_content) do
       appointment_list = subview(@appointment_list_screen.view)
    end
    # do something with `content` here
  end
end

# appointments_list.rb
class AppointmentsListScreen < PM::TableScreen
  # do your table stuff here
end
stefanvermaas commented 10 years ago

Wonderful! Thanks

jamonholmgren commented 10 years ago

You bet!