ios - 解压缩文件进度在 block 内不起作用
<p><p>目前我正在使用 <a href="https://github.com/mattconnolly/ZipArchive" rel="noreferrer noopener nofollow">https://github.com/mattconnolly/ZipArchive</a>库来解压缩压缩文件夹。它工作正常,但我还想用它显示解压缩进度。我正在使用 ZipArchiveProgressUpdateBlock 获得解压缩进度,但进度条没有显示进度。检查下面的代码:</p>
<pre><code>ZipArchive *zip = [ init];
self.progressBarDownload.progress = 0;
self.lblProgress.text = @"Wait unzipping file";
ZipArchiveProgressUpdateBlock progressBlock = ^ (int percentage, int filesProcessed, int numFiles) {
NSLog(@"total %d, filesProcessed %d of %d", percentage, filesProcessed, numFiles);
self.progressBarDownload.progress = filesProcessed / numFiles;
if(filesProcessed==numFiles)
self.lblProgress.text = @"Done";
};
zip.progressBlock = progressBlock;
//open file
;
//unzip file to
overWrite:YES];
</code></pre>
<p><strong>到目前为止我所做的尝试:</strong></p>
<p>我也尝试将进度条ui更改放在主线程中,但仍然无法正常工作</p>
<pre><code>ZipArchiveProgressUpdateBlock progressBlock = ^ (int percentage, int filesProcessed, int numFiles) {
NSLog(@"total %d, filesProcessed %d of %d", percentage, filesProcessed, numFiles);
dispatch_sync(dispatch_get_main_queue(), ^{
//Your code goes in here
NSLog(@"Main Thread Code");
self.progressBarDownload.progress = filesProcessed / (float)numFiles;
if(filesProcessed==numFiles)
self.lblProgress.text = @"Done";
});
};
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>尝试将解压缩代码放在后台 GCD 线程上。</p></p>
<p style="font-size: 20px;">关于ios - 解压缩文件进度在 block 内不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22784845/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22784845/
</a>
</p>
页:
[1]