11
我正在使用NSOperationQueue,我想將新的NSOperations添加到NSOperationQueue。這是一個居住在我擁有的類的單例實例中的隊列。如果我可以通過傳遞委託將所有內容移動到靜態類中,它會使事情變得更加容易。我可以通過委託作爲參數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 - 或者我可以使用某種類型的塊嗎?