Passing Data Example

Delegates or Properties, take your pick. PROPERTIES Class A (ViewController) wants to communicate with Class B (ViewController) Before calling Class B, do the following: In Class B, create a @property NSString* receivedValue; In Class A, #import Class B then in the method that calls B (either prepareForSegue or didSelectRowAtIndexPath or some method where you present Class B view controller, do the following: Class B *calledVC = alloc/init calledVC.receivedValue = ‘whatever value you want to pass’; then call Class B VC Done!   DELEGATES Let’s say Class B wants to notify Class A that something has finished.  In Class B add this above your @interface: @protocol YourDelegateProtocol <NSObject> – (void)itemWillBePassed; @end… Read More

Continue Reading

Delegates & Protocols iOS

A complex subject to wrap your head around, i agree!  But its pretty cool once you get a working example going. Let’s think of a game where a lander comes down from the sky (presumably on Mars – since Mars is a hot topic lately) and deploys a  rover.  In Cocos2d, you put all your objects on a Layer object.  This means the layer class is the main class (analogous to a viewcontroller class contains buttons, views, labels, cells etc). You create a Lander object class because you want to re-use it everywhere in the game.  With every new level, you must create a new layer class but you can… Read More

Continue Reading