Ios 通过选择表格视图中的单元格更改CollectionView中的内容
我在一个视图控制器中有一个表视图和一个集合视图 在表视图中,我有图像的类别,在集合视图中有图像 选择单元格后,如何更改为“集合内容”视图Ios 通过选择表格视图中的单元格更改CollectionView中的内容,ios,objective-c,uitableview,uicollectionview,Ios,Objective C,Uitableview,Uicollectionview,我在一个视图控制器中有一个表视图和一个集合视图 在表视图中,我有图像的类别,在集合视图中有图像 选择单元格后,如何更改为“集合内容”视图 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int numberFromArray=[numbers objectAtIndex:indexPath.row]; NSString *link=[rec
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int numberFromArray=[numbers objectAtIndex:indexPath.row];
NSString *link=[recipeImages objectAtIndex:indexPath.row];
static NSString *identifier = @"Cell";
NSString *imagineURL=[recipeImages objectAtIndex:4];
rowIndex=indexPath.row+1 ;
NSString *strFromInt = [NSString stringWithFormat:@"%d",rowIndex];
NSString * urlValue = [imagineURL stringByReplacingOccurrencesOfString:@"X"
withString:strFromInt];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlValue]];
recipeImageView.image = [UIImage imageWithData:imageData];
[self.collection reloadData];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
recipeImageView = (UIImageView *)[cell viewWithTag:100];
// NSString *imagineURL=imageTest;
rowIndex=indexPath.row+1 ;
NSString *imagineURL=[recipeImages objectAtIndex:1];
NSString *strFromInt = [NSString stringWithFormat:@"%d",rowIndex];
NSString * urlValue = [imagineURL stringByReplacingOccurrencesOfString:@"X"
withString:strFromInt];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlValue]];
recipeImageView.image = [UIImage imageWithData:imageData];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo-frame.png"]];
button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(getPicture:) forControlEvents:UIControlEventTouchDown];
button.frame = recipeImageView.frame;
button.tag=indexPath.row;
[cell.contentView addSubview:button];
return cell;
}
您必须在
(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath
上进行更改。更新图像数组并更新UICollectionView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.imagesCollection = //get you images from wherever
[self.collectionView reloadData];
}
这是一种正常的逻辑 在tableView的
-(void)tableView:(UITableView*)tableView didSelectRowatineXpath:(NSIndexPath*)indexPath
委托方法中,在选定单元格时放置选定问题
选择您想要的一个UICollectionViewCell*cell=[myCollection cellForItemAtIndexPath:1]
并执行一些更改,如cell.text=@“text had changed”
。最后别忘了调用reloadData
HTH.这是为长安拍摄的,仅收集了一张图片。我更新我的问题。我想更改collectionView@NicoleSD你的第一个方法是什么?似乎您没有任何更改,只需调用
[self.collection reloadData]