C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了我可以通过委托作为参数目标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全部内容,希望文章能够帮你解决我可以通过委托作为参数目标c所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: