UICollectionView我的应用程序中有一个全屏幕.它水平滚动,每个单元格填充集合视图的边界.集合视图由a管理UIViewController.
鉴于每个"页面"都相当复杂,因此每个页面本身都需要由关联管理UIViewController.iOS 5支持视图控制器包含,因此子viewWillAppear:视图在附加和分离视图时应该接收适当的生命周期方法(例如,等).这种视图回收有多好?
从页面"1"滚动到"2",将创建一个新视图(因为在触摸期间两者可能同时在屏幕上).从页面"2"移动到"3",UICollectionView可以成功地使页面"1"的视图出列,但现在发生了什么?我会强制将视图插入视图控制器三吗?
id cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ident" forIndexPath:indexPath];
UIViewController *child_controller = [self controllerAtIndexPath:indexPath];
[child_controller setView:cell];
// ... and so on
Run Code Online (Sandbox Code Playgroud)
这感觉不对.但是,我无法想到在这种情况下正确重用视图的正确方法.我完全采取了错误的做法吗?
我在我的应用程序中使用UICollectionView,在单个单元格上使用手势识别器,允许用户"滑开"单元格以显示下面的更多数据.
问题是,我经常在CollectionView中重新加载数据; 因为应用程序每3秒钟左右收到一次更新.当细胞处于滑动过程中时,这会导致不需要的行为,同时可以重复使用集合视图单元.
用户将开始滑动单元格,应用程序将接收更新,reloadData,并且不同的单元格将开始接收手势,并开始滑动.
我已经尝试在幻灯片发生时禁用应用程序的更新,但这导致了应用程序内的其他复杂情况,所以我想知道是否有办法禁用单元格重用,(我最多只有20个单元格,所以我不喜欢我认为性能会大幅下降).
谢谢!
我真的,真的想为我的UICollectionView提供'静态'单元格,以及UITableView的旧时代.但我知道我们好男孩和女孩必须dequeueReusableCellWithReuseIdentifier:forIndexPath:用作我们细胞的工厂.所以我建议采用以下方案,并就其潜力提出反馈意见.到目前为止,它对我有用,但我害怕一个未知的陷阱.
#import "MyCellClass.h"
@implementation MyViewController {
MyCellClass *_cell0; // etc - many are possible. could store in array
}
-(void)viewDidLoad {
// assume MyCellClass has a +nib and +reuseId. The reader understands.
[_collectionView registerNib:[MyCellClass nib] forCellWithReuseIdentifier:[MyCellClass reuseId]];
}
-(void)viewDidAppear:animated {
// this is where the fun begins. assume proper counts coming from the datasource
NSIndexPath *indexPath = [NSIndexPath indexPathWithRow:0 inSection:0];
_cell0 = [[self collectionView] dequeueReusableCellWithReuseIdentifier:[MyCellClass reuseId] forIndexPath:indexPath];
// etc
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath …Run Code Online (Sandbox Code Playgroud) 在我的tableview中,我需要一堆(5-6种)不同的单元格.所有项目都具有相同的视觉布局,但内容明智(标签名称,图片和颜色),它们有很大不同.
所以我有一个CustomUITableViewCell基类,在Interface Builder中使用这种通用设计设计.这个CustomUITableViewCell类服务器作为一堆单元子类的基类.我使用工厂模式从工厂类中使用类方法生成这些子类.这些子类没有xib.为什么他们会有共同的设计.
现在的问题是,对于每个子类,我需要一个不同的重用标识符.所以,人们会认为让我们覆盖每个子类的默认初始化器,并在其中调用另一个初始化器,即initWithStyle:reuseIdentifier:.
问题是需要指定样式.nil它不能放在那里,它抱怨.但我不需要Apple的任何风格,我显然有自己的风格,如果我想要一个股票风格,为什么我会做自定义设计.我只需要指定reuseIdentifier.
如果它只是readonly属性,如何分配重用标识符,似乎提供它的唯一方法是通过初始化程序?
背景为黑色,单元格为白色,尽管任何单元格都未显示,但是没人simulator?会知道为什么会这样吗?
import UIKit
import Foundation
class ChatLog: UICollectionViewController, UITextFieldDelegate, UICollectionViewDelegateFlowLayout {
let cellId = "cellId"
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor.black
collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cellId)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
cell.backgroundColor = UIColor.white
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: …Run Code Online (Sandbox Code Playgroud)