【问题标题】:Multiple UiCollectionview Reload issue多个 UiCollectionview 重新加载问题
【发布时间】:2017-09-25 06:02:12
【问题描述】:

我以编程方式创建了多个UICollectionView,并且我设置的值动态工作正常。我现在只想更新 3 UICollectionView。如何重新加载它。

下面我附上了我的代码:

for (int i=0; i<4; i++) {
    CGFloat x =0;
    CGFloat viewWidth = CGRectGetWidth(self.view.frame);
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];

    collectionview =[[UICollectionView alloc] initWithFrame:CGRectMake(0,0, viewWidth, 160) collectionViewLayout:layout];

    collectionview.backgroundColor=[UIColor clearColor];
    collectionview.tag=i;
    [collectionview setTag:i];
    [collectionview registerNib:[UINib nibWithNibName:@“Cell” bundle:nil] forCellWithReuseIdentifier:@“Cell”];

    collectionview.delegate=self;
    collectionview.dataSource=self;

    [self.view addSubview:collectionview];
    x=x+viewWidth;        
}

【问题讨论】:

  • 请出示相关代码
  • 您已经以编程方式创建了 3 个集合视图,您需要创建它的全局(强)对象。并使用 reloadData() 方法重新加载集合视图
  • colview1.reloadData()colview2.reloadData()colview3.reloadData(),就是这样。
  • for (int i=0; i
  • @dahiya_boy 我正在编程创建。检查我的代码。

标签: ios objective-c xcode uicollectionview


【解决方案1】:

使用 viewWithTag 获取 collectionView。

UICollectionView *Collection = (UICollectionView *)[self.view viewWithTag:3];

然后,只需重新加载数据或做任何事情:

[Collection reloadData];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 2020-02-25
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多