NSString 值在 -(id)init 之后更改

发布于 2024-12-05 08:12:44 字数 1544 浏览 0 评论 0原文

好的,有人告诉我延迟

-(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 之前的字符串值。

有人可以帮忙吗?

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.

Here's my code for the 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;

}

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. then xSheetMusicViewController tries to grab the string value, but it's still null from launch. 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.

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我为君王 2024-12-12 08:12:44

将您的设置代码从 init 移出并移至稍后可以调用的单独方法中。

Move your setup code out of init and into a separate method that can be called later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文