NSString值更改后 - (id)init

时间:2011-09-18 16:06:07

标签: iphone objective-c ios ipad nsstring

好的,所以我被告知延迟

是一个糟糕的主意
-(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尝试获取字符串值,但它在启动时仍然为null。然后从

更新值
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

方法,这意味着我不得不以某种方式延迟 - (id)init方法或找到更快的方法来更新init之前的字符串值。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

将您的设置代码移出init,并转换为稍后可以调用的单独方法。