我可以通过委托作为参数目标c

我正在使用NSOperationQueue,我想添加新的NSOperations到NSOperationQueue.它是一个排队,生活在一个类的单身实例.如果我可以通过传递代理将所有内容移动到静态类中,这将使事情变得更加容易.

这是我现在的代码,因为它在一个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 – 或者我可以使用某种块?

解决方法

只需创建适当的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;
}

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...