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

数据源方法不会创建大量临时view? #19

Open
shenfu1991 opened this issue Aug 8, 2017 · 2 comments
Open

数据源方法不会创建大量临时view? #19

shenfu1991 opened this issue Aug 8, 2017 · 2 comments

Comments

@shenfu1991
Copy link

// 返回 Banner 在不同的 index 所要显示的 View (可以是完全自定义的v iew, 且无需设置 frame)
- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index
{
    // 取出数据
    NSString *imageName = self.dataArray[index];
    
    // 创建将要显示控件
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:imageName];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    return imageView;
}

每次调用这个数据源方法就会产生一个临时的View(imageView),这样是不是有什么好的方法避免?

@zzyspace
Copy link
Owner

zzyspace commented Aug 9, 2017

这个数据源方法是banner滚动到当前index的时候才会调用, 不会导致创建大量的临时view. 不过的确是为了易用性没有考虑到重用. 下个版本会改成通过类似 dequeueReusableItemWithReuseIdentifier 的方式来获取重用的View.

@shenfu1991
Copy link
Author

shenfu1991 commented Aug 9, 2017

@zzyspace 感谢,还有个问题就是如果一开始数据源为空的话,右滑不能滑,具体看demo,文件链接:
http://www.wenjian.ml/Banner.zip

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

2 participants