YKPageView
YKPageView copied to clipboard
继承YKPageCell问题
我在FirstTableView继承YKPageCell后
- (YKPageCell *)pageView:(YKPageView *)pageView cellForIndex:(NSInteger)index { static NSString *identifier = @"pageCell"; FirstTableView *cell = [pageView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[FirstTableView alloc] initWithIdentifier:identifier]; } return cell; } 调用父类initWithIdentifier:方法,FirstTableView的frame是(0,0,0,0),请问是么原因导致的 qq:1183599228
你好 第一个cell的frame是在之后才确定的
initWithIdentifier的时候还没有确定frame
if (i == 0) {
YKPageCell *cell = [self.dataSource pageView:self cellForIndex:i];
cell.frame = frame;
[scrollView addSubview:cell];
[self.displayCells setObject:cell forKey:@(i)];
}
不是很明白下边的代码应该写到哪一块,能加到demo中吗
不是的,我的意思是,cell的frame会在之后被YKPageView自动设置
[self.dataSource pageView:self cellForIndex:i];是datasource创建并return的cell
之后,如果i==0(是第一个cell)
cell的frame会被自动设置
其后由于return的cell是从缓存池取出,所以已有frame就无需在设置了
@property (nonatomic, weak) YKPageView *pageView; 你demo中一定要用weak 属性么
@Eliothu 用strong也是一样的,pageView会被一直add到controller.view上,所以weak和strong差别不大