- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
didSelectRowAtIndexPath
方法在我的应用中不起作用。我没有使用 NSLog
打印任何输出:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
PhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
PFObject *imageObject = [self.imageFilesArray objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:@"file"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
cell.imageView.image = [UIImage imageWithData:data];
}
}];
return cell;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSLog(@"didSelectRowAtIndexPath");
cell.imageView.image = self.image;
return cell;
}
我希望当我点击一个单元格时,选择图像,并将图像提供给 self.image
。
我们可以在 segue 中实现吗?因为我的 didSelectRowAtIndexPath
方法根本不起作用。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showPhotoDetail"]) {
NSLog(@"SEGUE showPhotoDetail");
UICollectionViewCell *cell = sender;
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
PhotoDetailViewController *photoDetailViewController = (PhotoDetailViewController *)segue.destinationViewController;
photoDetailViewController.truckImage = self.image;
//[UIImage imageNamed:[self.imageFilesArray objectAtIndex:indexPath.row] ];
NSLog(@"%@", photoDetailViewController.truckImage);
}
}
最佳答案
你选择Item的方法签名是错误的,正确的方法签名是这个
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
尝试使用此代码获取所选图像。
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
PhotoCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
self.image = cell.imageView.image;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showPhotoDetail"]) {
// get index path of selected cell
NSIndexPath *indexPath = [collectionView.indexPathsForSelectedItems objectAtIndex:0];
// get the cell object
PhotoCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
// get image from selected cell
self.image = cell.imageView.image;
}
}
关于ios - UICollectionView didSelectRowAtIndexPath 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24527474/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!