我在一個視圖控制器中有一個表視圖和一個聚集視圖。通過選擇單元格表視圖更改CollectionView中的內容
在表格視圖中,我具有圖像類別和集合視圖圖像的類別。
如何選擇單元格時更改爲集合視圖的內容?
- (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;
}
這是changin只從集合中的一個圖像工作。我更新我的問題。 – 2015-02-24 17:03:30