Passing Data

Discussion in 'iOS Development' started by maxk96, Jul 22, 2010.

  1. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    I am using two different views and i have no idea how i could connect the UIImageView on iLightViewController to the UISwitch on SwitchVC.

    Apparently this is to do with passing data through view controllers. I really need help.
  2. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    You could either use NSNotificationCenter or use the owner of those two controllers to connect them.
  3. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    how could i use the owner to connect them?
  4. Mark Wough

    Mark Wough Banned

    Joined:
    Jul 22, 2010
    Messages:
    5
    Likes Received:
    0
    if you pass data by value then you are only passing the value stored in that variable. If you then change that value, in a method for example, it doesn't change the value in the original variable.

    On the other hand if you pass by reference, and you change the value, then it WILL change in the original variable.

    There will be times, such as when you work with arrays, that you might want to use the value stored in a particular spot in the array and use it in a calculation. Other times you will want to change the actual value in the array itself.
  5. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    If you post irrelevant bullsh*t in by value (this was copy-pasted from another forum) because you're trying to spam and sell stuff from your signature, by reference, even though this doesn't help answer the question at all, some people will notice.

    Reported.
    ------------------double post merged------------------
    @maxk96:

    You could use delegation.
    For example:
    [OBJC]@protocol SwitchVCDelegate

    - (void) switchViewController

    Please Register or Log in to view images

    SwitchVC*)controller didSelectImage

    Please Register or Log in to view images

    UIImage*img);

    @end
    [/OBJC]

    Look it up.
  6. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    thanks i now have an answer i can understand
    ------------------double post merged------------------
    i have tried numerous different ways and none of them have worked. One of them i thought worked made the app quite on load. Please could you have a look at my source code and try to get it to work. http://www.[PIRACY.mf].com/?ha1bajkar8s22bi
  7. MountainDew

    MountainDew New Member

    Joined:
    Feb 23, 2008
    Messages:
    194
    Likes Received:
    1
    Device:
    iPod touch
    I would use a Singleton class. When you change the switch's value, do something like this with a singleton:
    [OBJC][SingletonClass sharedInstance].someBool = switch.on;[/OBJC]
    Then in -viewDidLoad or -viewWillAppear:
    [OBJC]
    if ([SingletonClass sharedInstance].someBool) {
    //do something with imageView
    } else {
    //do something else with imageView
    }
    [/OBJC]

    http://stackoverflow.com/questions/...objective-c-singleton-look-like/145403#145403
  8. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    would you mind giving me an implementation of this in my code?
    Code:
    - (void)switchswitchRed {
    	if (switchRed.on) {
    		light.image = [UIImage imageNamed:@"Red.png"];
    	}
    }
  9. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    I don't mean to be condescending, and I'm terribly sorry if that is how I'm coming across, but I really don't feel like you should be anywhere NEAR an iPhone development setup, or any for that matter. I suggest you read up on your programming fundamentals, starting with C, which teaches you everything from data types and structures to pointers and arrays(all fundamental), to more things like memory management and data handling. At that point, Objective-C will be much easier to learn, as it derives from C. And, rather than trying to learn solely from source code(which don't get me wrong, is good, ONCE YOU KNOW WHAT YOU ARE DOING), read Apple's guides on the Objective-C runtime and syntax. It will teach you everything from creating your own classes, to subclassing other classes, to managing objects in memory and delegation. Trust me, you will be much better of if you take the time to learn properly. You then will not find yourself on a forum, in the development section, asking questions that shouldn't even register as appropriate, but simply trivial.
  10. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    lol, that made me smile, im young im still learning. I didnt see any code with your post.

Share This Page