[英]collectionView didSelectItemAtIndexPath with sending images
i am showing images in collection view. 我在集合视图中显示图像。 when i am selecting particular cell the detailed image will show in another viewcontroller. 当我选择特定的单元格时,详细的图像将显示在另一个viewcontroller中。 the delegate method is didSelectItemAtIndexPath. 委托方法是didSelectItemAtIndexPath。 please help me. 请帮我。
recipeImages = [NSArray arrayWithObjects:@"img2.png", @"img.png", @"img1.png", @"img3.png", @"img4.png", @"img5.png", @"img6.png", @"img7.png", nil];
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView1 cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
CustomCell *cell = (CustomCell *)[collectionView1 dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
[cell.imageView setImage:[UIImage imageNamed:[recipeImages objectAtIndex:indexPath.row]]];
return cell;
}
Check the below code: 检查以下代码:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *senderImg=[recipeImages objectAtIndex:indexPath.item];
NextViewController *next = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
next.receivedImage=senderImg;
[self presentModalViewController:next animated:NO];
}
NextViewController.h NextViewController.h
@property(nonatomic,retain)NSString *receivedImage;
NextViewController.m NextViewController.m
@syntosize receivedImage;
-(void)viewDidLoad
{
UIImage imageDispay=[UIImage imageNamed:receivedImage];
}
Check the below code: 检查以下代码:
- (void)collectionView:(UICollectionViewCell *)collectionView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"MyCell" bundle:[NSBundle mainBundle]];
detailVC.img= [recipeImages objectAtIndex: indexPath.row];
[self presentViewController:detailVC animated:YES completion:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.