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

标签 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 尝试获取字符串值,但启动时它仍然为空。然后该值从

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

方法,这意味着我要么必须延迟 -(id)init 方法,要么找到一种更快的方法来更新 init 之前的字符串值。

有人能帮忙吗?

最佳答案

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

关于iphone - NSString 值在 -(id)init 之后更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7462667/

相关文章:

iphone - 滚动 UIDatepicker 滚轮时出现错误位置

iphone - editButtonItem 设置但没有减号按钮?

ios - 在应用程序启动时在 iOS 模拟器中获取用户坐标

ios - 关闭AVPlayer的音频播放?

iOS:使用 MapBox 为出现在用户输入中的注释创建动态语音气球

ios - 如何检查 CLLocationCoordinate2D 不为空?

ios - UISystemGateGestureRecognizer 和屏幕底部附近的延迟点击

iphone - 在 didFinishLaunchingWithOptions 中将 View 显示为启动屏幕

objective-c - 如何使用swift检测tvOS越狱

ios - 将 Objective-C 转换为 Swift 时如何处理 Protocol Delegate