Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

继承YKPageCell问题 #3

Open
loverjiao0321 opened this issue Nov 12, 2015 · 6 comments
Open

继承YKPageCell问题 #3

loverjiao0321 opened this issue Nov 12, 2015 · 6 comments

Comments

@loverjiao0321
Copy link

我在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
@wangmchn
Copy link
Owner

你好 第一个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)];
}

@loverjiao0321
Copy link
Author

不是很明白下边的代码应该写到哪一块,能加到demo中吗

@wangmchn
Copy link
Owner

不是的,我的意思是,cell的frame会在之后被YKPageView自动设置
[self.dataSource pageView:self cellForIndex:i];是datasource创建并return的cell
之后,如果i==0(是第一个cell)
cell的frame会被自动设置

@wangmchn
Copy link
Owner

其后由于return的cell是从缓存池取出,所以已有frame就无需在设置了

@Eliothu
Copy link

Eliothu commented Nov 23, 2015

@Property (nonatomic, weak) YKPageView *pageView; 你demo中一定要用weak 属性么

@wangmchn
Copy link
Owner

@Eliothu
用strong也是一样的,pageView会被一直add到controller.view上,所以weak和strong差别不大

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants