[英]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.