在我的 AppDelegate 中,靠近 init 方法的末尾,我调用了一个 [self setup] 方法。此方法从 URL 中获取字符串,对其进行修剪,并将字符串分配给名为 _songDirectory 的属性。
下面是它在头文件中的样子:
@property (retain) NSString *_songDirectory;
以下是它在 [setup] 方法中的分配方式:
//set a URL string
NSString *urlString = [NSString stringWithFormat:@"http://www.blahblahblah.com/php/dev/blah.php?routine=blah"];
NSMutableString *infoString = [self getInfoStringFromURL: urlString];
//get the song directory as a string from the infostring
NSRange startIndex = [infoString rangeOfString:@"song_directory=="];
NSRange endIndex = [infoString rangeOfString:@"end_of_data=="];
_songDirectory = [NSString stringWithString: [infoString substringWithRange: NSMakeRange(startIndex.location + startIndex.length, endIndex.location - startIndex.location - startIndex.length)]];
NSLog(@"STRING IN APP DELEGATE: %@", _songDirectory);
NSLog 在应用程序委托中调用时打印正确的字符串。但是,在我推送新场景后,我无法从中访问 _songDirectory。推送场景中的以下代码产生 EXC_BAD_ACCESS:
NSLog(@"STRING IN PUSHED SCENE: %@", [[[UIApplication sharedApplication] delegate] _songDirectory]);
我可以使用上面的语句从应用程序委托中获取整数,而不是字符串。我会很感激一些见解!