简体   繁体   English

NSString值更改后-(id)init

[英]NSString Value Changed AFTER -(id)init

OK, so I've been told it's a terrible idea to delay the 好,所以有人告诉我,延迟

-(id)init

part of my code, but unfortunately it is NSLogging a NULL value before the string has time to register a change. 我的代码的一部分,但不幸的是,在字符串有时间注册更改之前,NSLogging NULL值。

Here's my code for the id init 这是我的ID初始化代码

- (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;

} }

and here's the Console Output: 这是控制台输出:

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

The original NULL value was from app launch, when it should be null (after all, why would I need the string at launch?) but then it mentions that it "failed to find the PDF header" which is quite new to me. 最初的NULL值来自应用程序启动,当它应该为null时(毕竟,为什么在启动时我需要字符串?),但是随后提到它“未能找到PDF标头”,这对我来说是很新的。 then xSheetMusicViewController tries to grab the string value, but it's still null from launch. 然后xSheetMusicViewController尝试获取字符串值,但是从启动开始它仍然为null。 Then the value is updated from a 然后从

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

method which means that somehow I either have to delay the -(id)init method or find a faster way to update the value of the string before the init. 方法,这意味着我要么必须延迟-(id)init方法,要么找到一种更快的方法来在初始化之前更新字符串的值。

Can anyone help? 有人可以帮忙吗?

将安装代码移出init并移到一个单独的方法中,以后可以调用该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM