为了在类之间共享数据,您可以使用通知机制。在您的FromClass.m中发布通知:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:yourTCPData, @"TCPData", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"gotTCPData" object:nil userInfo:options];
在你的ToClass.m viewDidLoad 添加这个:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(makeSomeThingUsefulWithTCPData:)name:@"gotTCPData" object:nil];
...并在您的ToClass.m中的某处添加此方法:
- (void)makeSomeThingUsefulWithTCPData:(NSNotification *)notification {
NSDictionary *dict = [notification userInfo];
yourTCPDataClass *yourTCPDataObject = [dict objectForKey:@"TCPData"];
// Here make something useful with your TCP data
}
还要在您的ToClass.m viewDidUnload 中添加它以在视图将被卸载时释放观察者对象:
[[NSNotificationCenter defaultCenter] removeObserver:self];