Reputation: 664
I've just a general theory question i was hoping to generate some responses. I've been learning ios and have a project with one view i'm tinkering with. It has a run loop that manages a socket that connects to a server and gets chat as it comes in. a textview is updated with new chat. Now this textview is attached to story board one. I'm going to ask now if they go to story board two when i add it (i'm reading up on this multi page aspect now), would the chat in view one continue to update though the user of course would not see it till they return o the view. The second question is could i update story board 2 and one at the same time in the first view controller. I saw you can pass variables to story board 2 in my book in the segue, but can my socket run loop which lives in view controller one access view controller two variables. If not it sounds like i need to investigate some kind of queue to communicate updates from telnet to story board 2.
Upvotes: 2
Views: 146
Reputation: 2984
You're starting off with a pretty complicated project - very impressed. Here are a couple of quick notes on storyboard and segues.
if you setup your storyboard using a view controller then setup a segue to another view controller - when you segue the new view controller is created, the original is still in memory and can still respond to notifications or callbacks if you program it that way.
when you "pop" or "dismiss" your view controller you segued to, it is gone from memory.
when you segue, you automatically get a reference to the new view controller in a method that is called prepareForSeque
. You can store this reference in a property and use that property to update it as needed.
So here is a pseudo example:
task - setup a reference for view controller b. in the import section of your view controller a .h file
#import "ViewControllerB.h" //this is the name of your view controller b class
in view controller a in the interface section (.h file) add:
@property (nonatomic, strong) ViewControllerB *viewB;
in your .m file you would trigger you segue - maybe on a button or some action. sounds like you already have this:
[self performSegueWithIdentifier:@"viewB" sender:self];
Now create a new method that looks like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
self.viewB = segue.destinationViewController; //this stores a reference for later
}
Now in your callback method you can reference view controller b like this:
-(void)networkCallbackMethod:(NSString*)stringData {
if (self.viewB) {
[self.viewB myCustomMethodUsingPassedData:stringData];
}
}
then finally in view controller b you would have the matching method like this:
-(void)myCustomeMethodUsingPassedData:(NSString*)stringData {
//update the view here
}
that should roughly provide you a framework where you can setup two view controllers, segue and grab a reference and then update the new view controller as needed.
hope that helps. good luck.
Upvotes: 2