我可以通过委托作为参数目标c
发布时间:2020-12-16 05:38:14 所属栏目:百科 来源:网络整理
导读:我正在使用NSOperationQueue,我想添加新的NSOperations到NSOperationQueue.它是一个排队,生活在一个类的单身实例.如果我可以通过传递代理将所有内容移动到静态类中,这将使事情变得更加容易. 这是我现在的代码,因为它在一个cellForRowAtIndexPath NSString *k
我正在使用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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- using System.Data.OracleClient与using Oracle.
- ajax异步获取数据后动态向表格中添加数据(行)
- ruby-on-rails – 无法设置Heroku时区
- 我的react组件化开发道路(二) 分页 组件开发
- ruby-on-rails – Rails范围测试为零
- Objective OA中的Twitter OAuth和accessToken到G
- Using Flex/Deploying application / Creating a
- grep中的正则表达式包含A,B,C ……但不包含Z的文
- 文本框获取光标位置 ---- ctrl+enter换行
- 在Ruby中,tLABEL究竟是什么意思?
热点阅读