rubymotion-community / sugarcube

Some sugar for your cocoa. RubyMotion helpers.
Other
422 stars 66 forks source link

removeFromParentViewController #50

Closed DougPuchalski closed 11 years ago

DougPuchalski commented 11 years ago

Should there be a UIViewController.pop method to call removeFromParentViewController?

colinta commented 11 years ago

Not to call removeFromParentViewController; pop is the complement to push, so it should re-assign the list of view controllers, removing the last one on the stack (makes most sense with the UINavigationController)

DougPuchalski commented 11 years ago

I may be a bit confused. Are we both talking about this?

sugarcube/lib/sugarcube/uiviewcontroller.rb

class UIViewController

  def push(view_controller)
    self.addChildViewController(view_controller)
    view_controller.didMoveToParentViewController(self)
    self
  end

  ...
end
colinta commented 11 years ago

Right, so push accepts the child controller as an argument, and pop would remove that same child. Maybe I misunderstood what you are recommending, but it sounded like

def pop
  removeFromParentViewController
end

Did I misunderstand?

DougPuchalski commented 11 years ago

Yes that's what I was suggesting, I wasn't sure I understood your first response. Seems like if you have a push you should have a pop.

colinta commented 11 years ago

I thought about it and I might add it, but it would look like this:

def pop
  to_pop = self.childViewControllers[-1]
  to_pop.removeFromParentViewController
end

That way it would work like UINavigationController's pop method (and Array for that matter!)

DougPuchalski commented 11 years ago

Yes that's totally right, my mistake. Or even if it takes an optional parameter for the controller. In general I like the idea where if you have a push you should have a pop.

GantMan commented 11 years ago

@colinta, let me know if you want me to toss this into the code/write tests for it.

colinta commented 11 years ago

Sure if you have a sec! I'm busy just trying to keep up with email this week :-)

On Mar 28, 2013, at 5:05 PM, Gant Laborde notifications@github.com wrote:

colinta, let me know if you want me to toss this into the code/write tests for it.

\ Reply to this email directly or view it on GitHub.

GantMan commented 11 years ago

This issue should be ready to be closed :)

colinta commented 11 years ago

Thanks again, @GantMan!