Add a picture in an array

Discussion in 'iOS Programming' started by Paandaman, Apr 4, 2012.

  1. Paandaman macrumors newbie

    Joined:
    Jan 26, 2012
    #1
    Hello everyone!

    I'm trying to create an app as a project in school and i managed to find a tutorial on youtube that explained just how to do so my app currently looks like this:

    http://youtu.be/iv3aLEyYM7w

    So it's constructed by a MasterViewController with a DetailViewController, the thing is that i would like to add a separate picture in each array that is going to explain the text i've written. So my question is: Is it possible to do that? And if, how do you do it?

    Any help would be greatly appreciated!
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Hey man,

    I would suggest creating an NSObject, that will be your Model for your "item", like, "Tip.h/m", this will hold text, title, image.
    Now create a loop over everything you have from data, to create these models,and set their PROPERTIES to the corresponding keys. (like i mentioned above).

    Then you have an array filled with NSObjects/Models from "Item", now you can create an Item for the row you clicked like.

    Code:
    Item *item = [self.itemArray objectAtIndex:indexPath.row];
    
    Now you can acces that property to send to your detail view controller, or just send the image it contains, it's a bit of MVC pattern, you should look into it, or research a bit more, or send me PM with more info.
     
  3. Paandaman thread starter macrumors newbie

    Joined:
    Jan 26, 2012
    #3
    Thanks man!

    I will look into it and see if i can get it to work out!
    Do i need to create a separate NSObject for each Tip or did i misunderstand?
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    Create a new file, which will be an NSObject, and you will name it "Tip", or "Item", or whatever you will use, give it a LOGIC name for an OBJECT with PROPERTIES (i'm cappsing important words).
    once you have created PROPERTIES on them, so you can set them, you can also create an custom Init method, but just properties will do.

    After, you will have to create a new "Tip" or "Item", or whatever your name is, pointer. So you will have to import that header file of your newly created NSObject (because it inherits from NSObject).
    So then in your data class you can make pointers to it like
    Tip *tip = [[Tip alloc] init];

    If you have no idea what i'm saying, please try to follow the iTunes classes from Stanford.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    The concept that jnoxx is trying to describe is called subclassing. And subclassing NSObject is frequently how you create a model class. Once you've defined it, you create instances of it and populate them as desired.

    And you don't necessarily need to consult the Stanford classes to learn about this. Any resource that covers the fundamentals of Objective-C programming should cover this topic fairly early on.
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    Agreed to Dejo, it's not necessary to check out the Stanford ones in perticular, but they are free video tutorials with hands on code and applications, which might help you to study the concepts of Objective-C faster :)

    Just my extra ^_-
     
  7. Paandaman thread starter macrumors newbie

    Joined:
    Jan 26, 2012
    #7
    Thanks a lot both of you! I somehow managed to work it out and the result is indeed satisfiying!

    I've only read through the "BecomeAnXcoder" book this far so i guess it won't hurt to check out the Stanford ones, thanks for the tip:)
     

Share This Page