Iphone 不';不工作队列

Iphone 不';不工作队列,iphone,objective-c,Iphone,Objective C,我有一个问题,我发现自己很难解决,所以我请求你的帮助 在FirstViewController.m中(FVC) 在SVC.h中 ...... - (void)blinkPic; ...... 在SVC.m中 - (void)viewDidLoad { [super viewDidLoad]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; ....... for (int i = 0; i < _picFor

我有一个问题,我发现自己很难解决,所以我请求你的帮助

在FirstViewController.m中(FVC)

在SVC.h中

......
- (void)blinkPic;
......
在SVC.m中

- (void)viewDidLoad
{
[super viewDidLoad];

 NSOperationQueue *queue = [[NSOperationQueue alloc] init];

 .......
 for (int i = 0; i < _picForDisplay.length; i++) { //picForDisplay can be from 0 to 10

 _forBlink = ......; // number of picture

   NSOperation *operation = [[NSInvocationOperation alloc]
                            initWithTarget:self
                            selector:@selector(blinkPic)
                            object:nil];

   [queue addOperation:operation];
 }
 .......
 }
 - (void)blinkPic
 {
   for (int i = 0; i < 18; i++) {

    if ( (i % 2 ) == 0 ){
        UIImageView *Pic = [self valueForKey:[NSString stringWithFormat:@"Pic%i",         _forBlink]];
        [Pic performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"1.png"] waitUntilDone:YES];

    } else {
        UIImageView *Pic = [self valueForKey:[NSString stringWithFormat:@"Pic%i", _forBlink]];
        [Pic performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"2.png"] waitUntilDone:YES];
    }

    [NSThread sleepForTimeInterval:0.1f];
  }
 }
-(void)viewDidLoad
{
[超级视图下载];
NSOperationQueue*队列=[[NSOperationQueue alloc]init];
.......
对于(int i=0;i<_picForDisplay.length;i++){//picForDisplay可以是0到10
_forBlink=……;//图片数量
NSOperation*操作=[[NSInvocationOperation alloc]
initWithTarget:self
选择器:@selector(blinkPic)
对象:无];
[队列添加操作:操作];
}
.......
}
-(无效)闪烁
{
对于(int i=0;i<18;i++){
如果((i%2)==0){
UIImageView*Pic=[self-valueForKey:[NSString stringWithFormat:@“Pic%i”,用于闪烁]];
[Pic performSelectorOnMainThread:@selector(setImage:)with object:[UIImage ImageName:@“1.png”]waitUntilDone:是];
}否则{
UIImageView*Pic=[self-valueForKey:[NSString stringWithFormat:@“Pic%i”,用于闪烁]];
[Pic performSelectorOnMainThread:@selector(setImage:)with object:[UIImage ImageName:@“2.png”]waitUntilDone:是];
}
[NSThread sleepForTimeInterval:0.1f];
}
}
如果我超过1,那么必须创建一些线程,让每个人都使用blinkPic方法,其中具有指定数字的图片(Pic)必须更改为图像的18倍-以闪烁

问题-如果图片1(i=0),则blinkPic方法的性能完全通过,图片“闪烁”

如果有更多图片(i=1或2或3等),则始终对最后一张图片执行blinkPic方法,所有其他图片保持不变。 当图片不止一张时,为什么不对所有图片执行blinkPic方法? 但是只有最后一个(

for(int i=0;i<\u picForDisplay.length;++i){//picForDisplay可以是0到10
NSOperation*操作=[[NSInvocationOperation alloc]
initWithTarget:self
选择器:@selector(blinkPic:)
对象:@(i)];
[队列添加操作:操作];
}
.......
}
-(无效)blinkPic:(NSNumber*)用于Blink
{
对于(int i=0;i<18;i++){
如果((i%2)==0){
UIImageView*Pic=[self-valueForKey:[NSString stringWithFormat:@“Pic%@”,forBlink]];
[Pic performSelectorOnMainThread:@selector(setImage:)with object:[UIImage ImageName:@“1.png”]waitUntilDone:是];
}否则{
UIImageView*Pic=[self-valueForKey:[NSString stringWithFormat:@“Pic%@”,forBlink]];
[Pic performSelectorOnMainThread:@selector(setImage:)with object:[UIImage ImageName:@“2.png”]waitUntilDone:是];
}
[NSThread sleepForTimeInterval:0.1f];
}
}

请格式化您的文本,它很难理解,甚至很难编辑,因为它可能会改变原始含义
- (void)viewDidLoad
{
[super viewDidLoad];

 NSOperationQueue *queue = [[NSOperationQueue alloc] init];

 .......
 for (int i = 0; i < _picForDisplay.length; i++) { //picForDisplay can be from 0 to 10

 _forBlink = ......; // number of picture

   NSOperation *operation = [[NSInvocationOperation alloc]
                            initWithTarget:self
                            selector:@selector(blinkPic)
                            object:nil];

   [queue addOperation:operation];
 }
 .......
 }
 - (void)blinkPic
 {
   for (int i = 0; i < 18; i++) {

    if ( (i % 2 ) == 0 ){
        UIImageView *Pic = [self valueForKey:[NSString stringWithFormat:@"Pic%i",         _forBlink]];
        [Pic performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"1.png"] waitUntilDone:YES];

    } else {
        UIImageView *Pic = [self valueForKey:[NSString stringWithFormat:@"Pic%i", _forBlink]];
        [Pic performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"2.png"] waitUntilDone:YES];
    }

    [NSThread sleepForTimeInterval:0.1f];
  }
 }
 for (int i = 0; i < _picForDisplay.length; ++i) { //picForDisplay can be from 0 to 10
   NSOperation *operation = [[NSInvocationOperation alloc]
                            initWithTarget:self
                            selector:@selector(blinkPic:)
                            object:@(i)];

   [queue addOperation:operation];
 }
 .......
 }
 - (void)blinkPic:(NSNumber*) forBlink
 {
   for (int i = 0; i < 18; i++) {

    if ( (i % 2 ) == 0 ){
        UIImageView *Pic = [self valueForKey:[NSString stringWithFormat:@"Pic%@", forBlink]];
        [Pic performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"1.png"] waitUntilDone:YES];

    } else {
        UIImageView *Pic = [self valueForKey:[NSString stringWithFormat:@"Pic%@", forBlink]];
        [Pic performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"2.png"] waitUntilDone:YES];
    }

    [NSThread sleepForTimeInterval:0.1f];
  }
 }