T
T
Toly2015-03-23 22:47:50
Cocoa
Toly, 2015-03-23 22:47:50

How to implement progress movements in NSProgressIndicator?

How to properly implement progress movement in NSProgressIndicator (determinate)?
Now I have implemented it like this:

IBOutlet NSProgressIndicator *progressIndicator;

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *content = [fileManager contentsOfDirectoryAtURL:url includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];

        double countList = (double)[content count];
        [progressIndicator setIndeterminate:NO];
        [progressIndicator setMinValue:0.0];
        [progressIndicator setMaxValue:countList];
        [progressIndicator setDoubleValue:0.0];

        for (NSURL *u in content) {
           Element *e = ;
           [list addObject:e];
           [progressIndicator incrementBy:1.0];
        }

I understand that setting setMaxValue: the number of files is wrong. Those. progressIndicator must be in a fixed range, such as 0 to 100, and its progress, or incrementBy:count in the sense of count, must be calculated using a formula.
Can you please tell me the formula how to correctly calculate the movement of progress?
Or if there are other options for implementing the NSProgressIndicator movement, describe them, preferably give an example or give a link to a useful article.
Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
feniksqip, 2015-04-01
@feniksqip

Try to solve mathematically: Take the approximate amount of data, for example 50 files per 100% (max scale level) = X and consider the increment as a division: X% 50 (your degree of smoothness). Getting the amount of data to send in a separate thread:
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSOperation *loadObj = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadInBackground:)
object:yourObj];
[queue addOperation:loadObj];

A
AmikoYuki, 2015-03-26
@AmikoYuki

Googled: NSProgressIndicator+ThreadSafeUpdating

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question