如何使用UIProgressView显示NSData写入和读取?

时间:2015-07-10 10:01:59

标签: ios nsdate nstimer nsthread uiprogressview

作为标题,我想知道在iOS设备中写入或读取NSData的进度,使用UIProgressView显示它,使用NSThread写入数据并使用NSTimer检查文件大小,但我没有成功。

我该怎么做?

- (void)load:(long)section {
    //set Timer
    float theInterval = 0.01f;

    copyFileTimer = [NSTimer scheduledTimerWithTimeInterval:theInterval target:self selector:@selector(progressFile) userInfo:nil repeats:YES];        
    [NSThread detachNewThreadSelector:@selector(writeFile:) toTarget:self withObject:nil];
}

- (void) writeFile:(id)sender {
    [movieData writeToFile:moviePath atomically:YES];
}

- (void)progressFile {
    NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:moviePath error:nil];
    NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
    NSInteger fileSize = [fileSizeNumber integerValue];

    [self updateProgress:(float)fileSize / (float)size];
    currentPer.text = [NSString stringWithFormat:@"%.0f%%", (float)fileSize / (float)size * 100];
    if ((float)fileSize / (float)size == 1) {
        [copyFileTimer invalidate];
    }
}

0 个答案:

没有答案