gpt4 book ai didi

ios - 一个 View 中的多个UICollectionView更新第二个UICollectionView数据

转载 作者:行者123 更新时间:2023-12-01 18:42:35 24 4
gpt4 key购买 nike

我想像图像一样设计。我使用两个UICollectionView进行设计。但是在快速单击UICollectionview行后,我无法更新第二个UICollectionView数据。我从不认为这是正确的方法。请提出任何建议。我需要使用Objective-C。

enter image description here

我的代码:

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
if (view.tag == 1) {
return 20;//SelfiThemeIm;age.count
} else {
return 15;
}
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (cv.tag == 0) {
TopCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"TopCell" forIndexPath:indexPath];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemeImage[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];

return cell;
} else {
BottomCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"BottomCell" forIndexPath:indexPath];

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemePhysicalFileName[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];

return cell;
}
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *ThemeURL;

if (collectionView.tag == 1) {
ThemeURL = @"http://wap.shabox.mobi/sticker_app_server/content.aspx?catid=";
ThemeURL =[ThemeURL stringByAppendingString:[SelfiThemeImageContentCode objectAtIndex:indexPath.row]];

BottomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BottomCell" forIndexPath:indexPath];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:ThemeURL
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *array= [responseObject objectForKey:@"stickers"];

self.selfidata = array;

// NSLog(@"JSON responce Selfi: %@", self.selfidata);

for(int i=0; i<=self.selfidata.count-1; i++){
NSString *PhysicalFileName = @"http://wap.shabox.mobi/CMS/content/graphics/Stickers/D200x200/";
PhysicalFileName =[PhysicalFileName stringByAppendingString:[[self.selfidata objectAtIndex:i]objectForKey:@"PhysicalFileName"]];
PhysicalFileName =[PhysicalFileName stringByAppendingString:@".png"];

[SelfiThemePhysicalFileName addObject:[NSString stringWithFormat:PhysicalFileName]];
NSLog(@"PhysicalFileName Array - %@", PhysicalFileName);
}

NSLog(@"SelfiThemePhysicalFileName Array - %@", SelfiThemePhysicalFileName);

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemePhysicalFileName[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}else{
}
}

最佳答案

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
if (view.tag == 1) {
return SelfiThemeImage.count;
} else {
return SelfiThemePhysicalFileName.count;
}
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (cv.tag == 0) {
TopCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"TopCell" forIndexPath:indexPath];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemeImage[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];

return cell;
} else {
BottomCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"BottomCell" forIndexPath:indexPath];

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemePhysicalFileName[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];

return cell;
}
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *ThemeURL;

if (collectionView.tag == 1) {
ThemeURL = @"http://wap.shabox.mobi/sticker_app_server/content.aspx?catid=";
ThemeURL =[ThemeURL stringByAppendingString:[SelfiThemeImageContentCode objectAtIndex:indexPath.row]];

BottomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BottomCell" forIndexPath:indexPath];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:ThemeURL
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *array= [responseObject objectForKey:@"stickers"];

self.selfidata = array;

// NSLog(@"JSON responce Selfi: %@", self.selfidata);

for(int i=0; i<=self.selfidata.count-1; i++){
NSString *PhysicalFileName = @"http://wap.shabox.mobi/CMS/content/graphics/Stickers/D200x200/";
PhysicalFileName =[PhysicalFileName stringByAppendingString:[[self.selfidata objectAtIndex:i]objectForKey:@"PhysicalFileName"]];
PhysicalFileName =[PhysicalFileName stringByAppendingString:@".png"];

[SelfiThemePhysicalFileName addObject:[NSString stringWithFormat:PhysicalFileName]];
NSLog(@"PhysicalFileName Array - %@", PhysicalFileName);
}

NSLog(@"SelfiThemePhysicalFileName Array - %@", SelfiThemePhysicalFileName);

[self.myCollectionView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}else{
}
}

我对您的代码进行了更改,只是将其替换为您的代码。

编码愉快。投赞成票

谢谢。

关于ios - 一个 View 中的多个UICollectionView更新第二个UICollectionView数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40858135/

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