简体   繁体   English

NSProgressIndicator将不会消失(确定)

[英]NSProgressIndicator will not disappear (determinate)

I have a determinate progress indicator. 我有一个确定的进度指示器。 It is working just like I would expect it to but it does not disappear after it reaches maxValue. 它的工作方式与我期望的一样,但是在达到maxValue后不会消失。 I have set the progress indicator to not display when stopped in the main.nib file, I have also entered it into the awakeFromNib{} method. 我已将进度指示器设置为在main.nib文件中停止时不显示,我也将其输入到awakeFromNib {}方法中。 I put a log at the end of the routine to make sure the [displayWhenStopped] setting was still set to NO and it is. 我在例程的末尾放置了一个日志,以确保[displayWhenStopped]设置仍设置为NO。

Here is my code : 这是我的代码:

-(void)getEvents:(NSURL *)mffFile{

NSMutableArray * eventTypeResults =[[NSMutableArray alloc]init];

EWaveformRecording  *ptrToRcdFile = [EWaveformRecording openRecording:mffFile permission:readOnly user:nil convertFileFormat:NO openReadOnlyAnyway:NO];
NSArray *events = [ptrToRcdFile getEvents];
//get the size of events for the progressbar and instantiate a loop counter
NSInteger total = [events count];
int loop = 0;

//set progress bar params
[self->meter_ setUsesThreadedAnimation:YES];
[self->meter_ setControlSize:NSMiniControlSize];
[self->meter_ setMaxValue:(double)total];

for(EEvent* event in events){
    loop ++;
    if(![eventTypeResults containsObject:event.code]){
     NSLog(@"check eventNames in getEvents %@", event.code);
     [eventTypeResults addObject: event.code];
    }//end if
//display loop increment in progress bar
[self->meter_ setDoubleValue:(1000*(double)loop)/1000];
}//end for

//send the eventTypesResults array to the EventExport class
[evtPtr setEventsAvailableList:eventTypeResults];
 }

What I have tried: 我尝试过的

with and without [setUsesThreadedAnimation] which I don't totally understand; 有和没有[setUsesThreadedAnimation],我不完全理解; it does slow down the progress bar which makes it look better but the docs say only indeterminate types should be effected by animation. 它确实减慢了进度条,使它看起来更好,但是文档说只有不确定的类型才应该受动画影响。

I have tried using [start & stop animation] I have tried [setDisplayWhenStopped:NO] after my loop 我尝试使用[开始和停止动画]在循环后尝试了[setDisplayWhenStopped:NO]

Any help is greatly appreciated MIke 任何帮助都非常感谢MIke

This is what I learned. 这是我学到的。

I should not be allowing the progress bar to run on a different thread even though it looks like its working because the NSProgressIndicator can no longer respond to the settings in the main thread, so the proper thing to do is to not instantiate that method, however , that was not the solution to my problem; 尽管NSProgressIndicator无法再响应主线程中的设置,但即使看起来像它在工作,我也不应该允许进度条在其他线程上运行,因此正确的做法是不要实例化该方法,但是,那不是我的问题的解决方案; I was doing everything else right, but the main thread could not redraw the progress because it's busy with all the other calls in the UI. 我在做其他所有事情都没做错,但是主线程无法重绘进度,因为它忙于UI中的所有其他调用。 The solution was to implement NSRunLoop so that each iteration of the loop interrupts the main thread and redraws the progress meter , then returns control. 解决方案是实现NSRunLoop,这样循环的每次迭代都会中断主线程并重绘进度表,然后返回控制权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM