传递数据只是没有诀窍...当我调用AppDelegate中的函数时,我需要从视图控制器中提取字符串数据。下面的代码:从功能上从视图控制器拉数据
在应用程序委托:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
AMViewController *viewController = [[AMViewController alloc] initWithNibName:@"AMViewController" bundle:nil];
self.xpData = viewController.xpLabel.text;
NSLog(@"Value of xpString in AD: %@", self.xpData);
}
在我的ViewController,我没有使用动作来传递/检索字符串。我基本上是从用户点击主页按钮时从ViewController拉它。我这样做是因为我想在退出时保存数据。谢谢!
当应用程序进入后台你要创建一个视图控制器的价值? xpLabel.text如何设置?我猜这不是。 – Bejmax
你用你写的代码在你的日志上得到什么?它是空的还是比你想要的还要有价值? – ashiina
'AMViewController * viewController = [[AMViewController alloc] initWithNibName:@“AMViewController”bundle:nil];'这将创建一个新的视图控制器。你需要的是现有的视图控制器。你是如何创建这个视图控制器?它是rootviewcontroller并在didFinidhLaunching方法中创建? – iDev