2012-06-13 4 views
11

NSOperationQueueを使用していて、NSOperationQueueに新しいNSOperationsを追加したいと思います。私が持っているクラスのシングルトンインスタンスに存在するキューです。デリゲートを渡すことですべてを静的クラスに移すことができれば、はるかに簡単になります。それはに住んでいるとしてここ代理人をパラメータobjective-cとして渡すことはできますか?

は私のコードは今ある - これは私が共有シングルトンクラスにこのコードのすべてを入れて、それを呼び出すことができ、パラメータとしてデリゲートを追加することができればcellForRowAtIndexPath

NSString *key = [NSString stringWithFormat:@"%@%@",cell.dataItem.ItemID, cell.dataItem.ManufacturerID]; 

     if (![self.imgOperationInQueue valueForKey:key]) { 

      ImageOperation *imgOp = [[ImageOperation alloc] initWithItemID:cell.dataItem.ItemID withManufacturerID:cell.dataItem.ManufacturerID withReurnType:kThumbnail]; 
      imgOp.identifier = [NSString stringWithFormat:@"%i", cell.tag]; 
      imgOp.delegate = self; 
      [[SharedFunctions sharedInstance] addImageOperationToQueue:imgOp]; 
      [imgOp release]; 

      // store these in the dictionary so we don;t queue up requests more than once 
      [self.imgOperationInQueue setValue:cell.dataItem.ItemID forKey:key]; 
     } 

にされます私のアプリのどこからでも。

私はNSNotificationを使用することができますか?または何らかのブロックを使用できますか?

答えて

20

デリゲートを渡す適切なinitメソッドを作成してください。

- (id)initWithItemID:(NSString *)itemID 
    withManufacturerID:(NSString *)manufacturerID 
     withReurnType:(NSInteger)type 
      delegate:(id<YourDelegate>)theDelegate 
{ 
    self = [super init]; 
    if (self) 
    { 
     .... // Other assignments 
     self.delegate = theDelegate; 
    } 

    return self; 
} 
関連する問題