gpt4 book ai didi

ios - 使用新数据重新加载 Collection View IOS7

转载 作者:行者123 更新时间:2023-11-28 22:08:47 25 4
gpt4 key购买 nike

您好,我正在开发小型 IOS 应用程序,我是 IOS 开发的新手。在我的应用程序中,我使用 Collection View 来显示我的数据。我在做什么 我正在从我的服务器获取数据,然后显示在我的 UIView Controller 中。这是我的代码看起来像

- (void)viewDidLoad
{
[super viewDidLoad];

// call for fetching data from server
}


// My collection view methods
-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}

-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section
{
return [_channelArray count];
}

-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

cell.image = // set image from channel array.
return cell;
}



// callback for m web service call
-(void) didReceiveSubscriberChannelList:(SubscriberChannelListDataModel *)subscriberChannelListInfo
{

_channelList = subscriberChannelListInfo;
_channelArray = subscriberChannelListInfo.chanellist;
[collectionView reloadData];
}

以上代码适用于静态数据。但是现在我想显示我的服务器数据。我的重新加载数据不起作用。这个怎么做。需要帮忙。谢谢。

最佳答案

有没有考虑过把回调方法的数据放在一个 block 中?

// callback for m web service call 
-(void) didReceiveSubscriberChannelList:(SubscriberChannelListDataModel *)subscriberChannelListInfo
{
dispatch_async(dispatch_get_main_queue(), ^{
_channelList = subscriberChannelListInfo;
_channelArray = subscriberChannelListInfo.chanellist;
[collectionView reloadData];
});
}

这样,当回调返回时,它会在主线程(UI线程)中重新加载数据

关于ios - 使用新数据重新加载 Collection View IOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23367829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com