代码之家  ›  专栏  ›  技术社区  ›  theprojectabot

发生awakefromnib后约10秒,ProgressIndicator才会更新。

  •  0
  • theprojectabot  · 技术社区  · 14 年前

    当文档加载到视图中时,我一直在尝试让我的UI的这一部分立即更新。awakefromnib触发粘贴的代码,然后启动计时器,每10秒重复一次…

    我加载默认存储位置:~/电影…马上就会出现……然而,保存在从XML中提取的文档中的网络位置似乎只在第二次触发-(void)updatediskspacedisplay计时器后出现。

    我已经设置了断点,并且知道包含要放入*文件系统属性中的值的ivar是发生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];
    }
    

    思想?

    我的灵感来自笔尖:

    - (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];
    }
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Josh Freeman    14 年前

    awakeFromNib 只是通知您的实例其iboutlet已设置,而不是通知应用程序已完成启动并准备就绪。

    尝试实现nsapplication的委托方法, applicationDidFinishLaunching: 打电话给你 updateDiskSpaceDisplay 方法。

        2
  •  0
  •   theprojectabot    14 年前

    我在awakefromnib之后,有一个从XML方法读取数据的方法,它正在转换值…我刚把最新的磁盘空间显示器放在那里…问题解决了。谢谢大家的努力。