1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Passing UIImage from UITableViewCell to another controller

Discussion in 'iPhone/iPad Programming' started by veliborsantic74, Sep 19, 2012.

  1. macrumors newbie

    As title says, how to accomplish it? I have 2 UIImageView on every cell which I want to pass to UIImageViews on another controller after user tap that cell?
  2. macrumors 6502a

    Duncan C

    You should not use the cells to store the image. You should have a data model that saves the data for every entry in your table.
    For non-sectioned table, your data model can be a simple array of NSDictionary objects. Each NSDictionary would contain keys for the different things you need to store for that table entry: Text for your label fields, images for your image views, etc.

    When the user taps a cell, the cellForRowAtIndexPath method gets the indexPath of the selected cell. It would use the row to index into your array of dictionaries, fetch the image(s) for that entry in your table, and then pass those to your next view controller.

    How you pass data to your next view controller depends on how your app is organized. Are you using storboard and segues? If so, you'd remember the row (or row and section) that the user tapped, then invoke a segue. Then in your prepareForSegue method, you'd use the row or row/section to look up the images and set them as properties in your second view controller.

    If you're not using storyboards you'd get a pointer to the other view controller (either by creating it on the fly, or saving it if you make it persist) then set the image properties and display that second view controller. (If you're using a navigation controller you'd push it. If not, you could present the second view controller as a modal.)

    Anyway, I'm not going to map out in detail all the steps for all the different ways your app could be structured. Provide more info about how your app works.
  3. macrumors newbie

    I would like to use solution by creating pointer for second view controller, but I don't know how to grab images from tapped cell row. Images are added on cell.content.view. So, how to get pointers from these images and simply forward them on corresponding UIImageViews?
  4. macrumors 6502a

    Duncan C

    Re-read my post. The first sentence tells you not to do that.

Share This Page