作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将图像从一个 View Controller (包含 Collection View )传递到另一个 View Controller ,但它没有发生。我是 iOS objective-c 的新手。谁能告诉我解决方案。这是我的代码...
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
DetailedAlbumViewController *davc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailedAlbumViewController"];
AlbumPhotoCollectionViewCell *cell = (AlbumPhotoCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
UIImage *image = cell.imageView.image;
[davc setImage:image];
//davc.imageView.image = image;
[self presentModalViewController:davc animated:YES];
}
在我的第二个 View Controller 中...
- (void) setImage:(UIImage *) image{
UIImage *someImage = [[UIImage alloc]init];
someImage = image; // image is passing upto here.. i.e. someImage is being allocated with the image passed from first view controller..
self.imageView.image = someImage; // here it is showing nil
}
我使用了调试控制台..输出是..
(lldb) po someImage
<UIImage: 0x79eb8590>, {500, 347}
(lldb) po self.imageView.image
nil
最佳答案
您只能将图像而不是设置图像传递给目标 Controller 。所以你需要编写如下代码。
在 DetailedAlbumViewController 中
@property (nonatomic, strong) UIImage *yourImage ;
在DetailedAlbumViewControllerv的viewDidLoad中
[self setImage:self.yourImage];
点击单元格
建议 - 您需要使用 didselectItemAtIndexpath 而不是 didDeselectItemAtIndexPath。
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
DetailedAlbumViewController *davc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailedAlbumViewController"];
AlbumPhotoCollectionViewCell *cell = (AlbumPhotoCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
UIImage *image = cell.imageView.image;
davc.yourImage = image
[self presentModalViewController:davc animated:YES];
}
关于ios - 在 View Controller 之间传递图像在呈现模态视图时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44878223/
我来自 Asp.Net 世界,试图理解 Angular State 的含义。 什么是 Angular 状态?它类似于Asp.Net中的ascx组件吗?是子页面吗?它类似于工作流程状态吗? 我听到很多人
我一直在寻找 3 态拨动开关,但运气不佳。 基本上我需要一个具有以下状态的开关: |开 |不适用 |关 | slider 默认从中间开始,一旦用户向左或向右滑动,就无法回到N/A(未回答)状态。 有人
我是一名优秀的程序员,十分优秀!