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?
Move your setup code out of init and into a separate method that can be called later.