How to display image in a detailed view from a table from plist?

Discussion in 'iOS Programming' started by spinedoc77, Oct 21, 2011.

  1. spinedoc77, Oct 21, 2011
    Last edited by a moderator: Oct 21, 2011

    spinedoc77 macrumors G3

    spinedoc77

    Joined:
    Jun 11, 2009
    #1
    I currently have a project which includes a table of items, clicking on a row for a particular item will bring you to a detail view which includes description text for the item. I'm currently pulling the items from a plist (dictionary array).

    I'd like to also add an image into the detailed view but am not sure how to go about it. This is how I am currently calling the items in my detailed view.

    Code:
    -(void) viewWillAppear: (BOOL)animated {
        [super viewWillAppear:animated];
        //set up UI with muscle names
        self.textField.text=[self.muscleNames objectForKey: NAME_KEY];
        self.textView.text=[self.muscleNames objectForKey: DESCRIPTION_KEY];
    }
    I know images cannot be stored in the plist itself, but can I put in a pointer to the image file, which would be in the supporting files? I can set up UIImageView and link it up, but I'm not sure how to implement it.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    The simplest thing to do is simply put the image file name in the plist and use that to create the UIImage to display in the view.
     
  3. spinedoc77, Oct 21, 2011
    Last edited by a moderator: Oct 21, 2011

    spinedoc77 thread starter macrumors G3

    spinedoc77

    Joined:
    Jun 11, 2009
    #3
    I've gotten this far, I'm just not sure how to call the image up in my method above. I've tried, for example,

    Code:
    self.imageView.image=[self.muscleNames objectForKey: IMAGE_KEY];
    This is linked with a UIIMageView element dragged in from IB in the detailed view.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    What is muscleImages? How is it setup/declared?
     
  5. spinedoc77 thread starter macrumors G3

    spinedoc77

    Joined:
    Jun 11, 2009
    #5
    muscleNames is a my plist dictionary, it works to display the name and description of what I am referencing.

    Code:
    @interface DetailedView : UIViewController {
    @private
        
        IBOutlet UITextView *textView_;
        IBOutlet UITextField *textField_;
        IBOutlet UIImageView *imageView_;
        NSDictionary *muscleNames_;
    }
    
    @property (nonatomic, retain) IBOutlet UITextView *textView;
    @property (nonatomic, retain) IBOutlet UITextField *textField;
    @property (nonatomic, retain) NSDictionary *muscleNames;
    @property (nonatomic, retain) IBOutlet UIImageView *imageView;
    
    @end[COLOR="#808080"]
    
    ----------
    
    [/COLOR]self.imageView.[B][COLOR="Red"]image[/COLOR][/B]=[self.muscleNames objectForKey: IMAGE_KEY];
    This is where I think I'm doing something wrong, I'm used to calling text.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    That does not answer the question. How is muscleNames setup. Where do you assign a value to it and populate the array?

    If it is a dictionary loaded from a plist what makes you think you can do what you are trying to do? The value assiged to self.imageview.image must be a UIImage. You are not assigning a UIImage. Look at the UIImage documentation and figure out how to turn a path into a UIImage instance
     
  7. spinedoc77 thread starter macrumors G3

    spinedoc77

    Joined:
    Jun 11, 2009
    #7
    In my first post I listed how I populate the array. I have a constant file that denotes each item as a constant ie:

    #define NAME_KEY @"name"
    #define DESCRIPTION_KEY @"description"
    #define IMAGE_KEY @"image"

    I'll take a look at Apple's documentation, it just seemed like something simple.
     

Share This Page