好的,所以我被告知推迟是一个糟糕的主意
-(id)init
我的代码的一部分,但不幸的是,它是在字符串有时间注册更改之前 NSLogging NULL 值。
这是我的 id init 代码
- (id)init {
if (self = [super init]) {
CFStringRef aCFString = (CFStringRef)[appDelegate baseURL];
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), aCFString, NULL, NULL);
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
NSLog(@"xSheetMusicViewController - %@",appDelegate.baseURL);
CFRelease(pdfURL);
}
return self;
这是控制台输出:
2011-09-18 09:52:22.275 SheetMuse[57499:b603] value - (null)
failed to find PDF header: `%PDF' not found.
2011-09-18 09:52:24.575 SheetMuse[57499:b603] xSheetMusicViewController - (null)
2011-09-18 09:52:24.581 SheetMuse[57499:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4e5a910>.
2011-09-18 09:52:24.624 SheetMuse[57499:b603] value - mussette.pdf
2011-09-18 09:52:24.627 SheetMuse[57499:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4cc1ba0>.
2011-09-18 09:52:24.628 SheetMuse[57499:b603] value - mussette.pdf
最初的 NULL 值来自应用程序启动,它应该为 null(毕竟,为什么我在启动时需要该字符串?),但随后它提到它“无法找到 PDF 标题”,这对于我。然后 xSheetMusicViewController 尝试获取字符串值,但启动时它仍然为空。然后该值从
更新- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
方法,这意味着我要么必须延迟 -(id)init 方法,要么找到一种更快的方法来更新 init 之前的字符串值。
有人能帮忙吗?
最佳答案
将设置代码从 init 移出并移至稍后可以调用的单独方法中。
关于iphone - NSString 值在 -(id)init 之后更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7462667/