簡體   English   中英

NSString值更改后-(id)init

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

好,所以有人告訴我,延遲

-(id)init

我的代碼的一部分,但不幸的是,在字符串有時間注冊更改之前,NSLogging NULL值。

這是我的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;

}

這是控制台輸出:

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並移到一個單獨的方法中,以后可以調用該方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM