I’ve a ViewController where I call a method from another class (TCP class), where I make a TCP connection to a server, that gives me a response. And I want to, when that TCP class, get’s the response from the server, call another method from the ViewController.
Problems:
- I’m a noob.
- I’m initializing and allocating that first
Viewcontroller on the TCP, and all my vars are reseted (something
that I don’t want).
So… What can I do to make it right? I just want to call a method from a different class, that is already allocated in memory.
Tks!
You could set up the ViewController as an observer to the TCP class. This is a link that explains an implementation of the observer pattern in Obj-C. (Very similar to what I use but in a nice write up.)
http://www.a-coding.com/2010/10/observer-pattern-in-objective-c.html
I usually like to separate the persistence layer from the interface as well. I use observers or KVO to notify my business logic and view controllers that something changed.
You can also send the information through the Notification Center that is provided if you prefer…
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsnotificationcenter_Class/Reference/Reference.html
Basic Code Example:
Hope that helps!