2012-06-13 16 views
11

NSOperationQueue ile çalışıyorum ve NSOperationQueue için yeni NSOperations eklemek istiyorum. Sahip olduğum bir sınıfın tek bir örneğinde yaşayan bir kuyruktur. Delegeyi geçerek her şeyi statik sınıfa taşıyabilseydim, işleri daha kolaylaştırabilirdi. o yaşıyor olarak burada Temsilci bir parametre hedefi olarak geçirebilir miyim?

şimdi benim kod - ı parametre olarak temsilci ekleyebilirsiniz paylaşmadım Singleton sınıfa bu kodun tüm koyup diyebiliriz Eğer bu bir 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]; 
     } 

içindedir Uygulamamdaki herhangi bir yerden.

Bir NSNotification kullanabileceğimi varsayalım - veya bir çeşit bloğu kullanabilir miyim?

cevap

20

Yalnızca temsilci içinden geçen uygun init yöntemini oluşturun.

- (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; 
} 
İlgili konular