当文档加载到视图中时,我一直试图让我的UI的这一部分立即显示日期。 awakeFromNib会触发粘贴的代码,然后启动一个计时器,每10秒重复一次......
我加载了一个默认的存储位置:〜/ Movies ...立即显示..但是从XML中提取的文档中保存的网络位置似乎只在第二次触发后显示 - (void)updateDiskSpaceDisplay计时器。
我设置了断点并且知道包含放入* fileSystemAttributes的值的ivars是awakeFromNib发生时的网络位置......
我很困惑为什么它在第二次射击后神奇地出现而不是立即显示写入值。
- (void)updateDiskSpaceDisplay
{
// Obtain information about the file system used on the selected storage path.
NSError *error = NULL;
NSDictionary *fileSystemAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[[[self settings] containerSettings] storagePath] error:&error];
if( !fileSystemAttributes ) return;
// Get the byte capacity of the drive.
long long byteCapacity = [[fileSystemAttributes objectForKey:NSFileSystemSize] unsignedLongLongValue];
// Get the number of free bytes.
long long freeBytes = [[fileSystemAttributes objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
// Update the level indicator, and the text fields to show the current information.
[totalDiskSpaceField setStringValue:[self formattedStringFromByteCount:byteCapacity]];
[totalDiskSpaceField setNeedsDisplay:YES];
[usedDiskSpaceField setStringValue:[self formattedStringFromByteCount:(byteCapacity - freeBytes)]];
[usedDiskSpaceField setNeedsDisplay:YES];
[diskSpaceIndicator setMaxValue:100];
[diskSpaceIndicator setIntValue:(((float) (byteCapacity - freeBytes) / (float) byteCapacity) * 100.0)];
[diskSpaceIndicator display:YES];
}
想法?
我的awakeFromNib:
- (void)awakeFromNib
{
[documentWindow setAcceptsMouseMovedEvents:YES];
[documentWindow setDelegate:self];
[self updateSettingsDisplay];
[self updateDiskSpaceDisplay];
[self setDiskSpaceUpdateTimer:[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateDiskSpaceDisplay) userInfo:NULL repeats:YES]];
[self setUpClipInfoTabButtons];
[self performSelector:@selector(setupEngineController) withObject:NULL afterDelay:0.1];
}
答案 0 :(得分:1)
awakeFromNib
只是通知您的实例已设置了IBOutlets,而不是应用程序已完成启动并准备好绘制。
尝试实施NSApplication的委托方法applicationDidFinishLaunching:,然后从那里调用updateDiskSpaceDisplay
方法。
答案 1 :(得分:0)
有一个xml方法的读取是在我的awakeFromNib之后发生的,它正在调整值...我只是把updateDiskSpaceDisplay放在那里......问题解决了。谢谢大家的尝试。