In Rubymotion how to get callback from dismissed view controller

160 Views Asked by At

On a table row click I reference a cell to present a view controller (to select from a list of images)

  def open_selector             
     view_b = ImagesController.new  #using rmq hence .new           
     @@cell.superview.superview.controller.presentViewController view_b, animated:true, completion:nil
  end

Inside the images controller - I dismiss when finished selecting - but how do I let cell know it was closed?

def collectionView(view, didSelectItemAtIndexPath: index_path)

  self.dismissViewControllerAnimated(true, completion: lambda{})

end
1

There are 1 best solutions below

0
Steve Ross On

I would suggest providing your UICollectionViewController a delegate so it can call back itself. So:

class MyCollectionViewController < UICollectionViewController
  attr_writer :parent_controller

  # ...

  def collectionView(view, didSelectItemAtIndexPath: index_path)
    self.dismissViewControllerAnimated(true, 
                                       completion: lambda{
                                       @parent_controller.collection_did_close(self)
                                       })
  end

Assuming, you have a method called collection_did_close in the parent controller, it will be called with a reference to the collection view controller. Using that you can grab whatever information you need out of there before it gets garbage collected.