[英]Dequeuing as per UITableView and UICollectionView
我想在自己的类中使用UITableView和UICollectionView中的出队模型,在这里将其称为CustomControl
。 我的目标是回收视图控制器而不是视图,但是我认为原理是相同的。 我对设计的想法是:
CustomControl
实例myCustomControl
的dataSource
。 使用者告诉myCustomControl
它想要对某个字符串标识符使用哪种视图:
[myConstomControl registerClass:[UIViewController class] forCellWithReuseIdentifier:@"StandardViewController"]; [myConstomControl registerClass:[SomeCustomController class] forCellWithReuseIdentifier:@"CustomController"];
CustomControl
在NSDictionary- -(void)registerClass:(Class)viewControllerClass forCellWithReuseIdentifier:(NSString *)identifier { [self.classRegister setObject:viewControllerClass forKey:identifier]; }
捕获此信息-(void)registerClass:(Class)viewControllerClass forCellWithReuseIdentifier:(NSString *)identifier { [self.classRegister setObject:viewControllerClass forKey:identifier]; }
-(void)registerClass:(Class)viewControllerClass forCellWithReuseIdentifier:(NSString *)identifier { [self.classRegister setObject:viewControllerClass forKey:identifier]; }
myCustomControl
刷新时,它将向datasource
询问控制器。 datasource
从myCustomControl
中使控制器出队,并传入所需的类型作为字符串标识符。 UIViewController *controller = [myCustomControl dequeueViewControllerWithIdentifier:@"StandardViewController"];
myCustomControl
回收或创建存储在字典中的类型的控制器,然后将其返回到datasource
,在该datasource
中对其进行自定义并返回到myCustomControl
以进行显示。 我欢迎对此模式发表评论,但对我来说似乎可行。 我不确定是否邻接出队部分:
Class
类型的对象? 有一个可变字典来保存数据。 关键字是“标识符”,而对象是一个新类的自定义对象,例如:reuseInfo。
自定义对象可以具有一个类名,即VC数组。
调用register方法后,您可以向字典中添加键,并使用类名和空数组(Mutable)创建自定义类
VC可以覆盖准备重用,以清理属性和其他值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.