0

我是 OS X 的新手,已经开始处理 NSCollectionView。我想要做的是用 imageView 数组显示 NSCollectionView 和标签。在选择图像时,我想打开一个新的 viewController 类。我能够在集合视图中显示图像和标签数组,但我完全不知道如何使用 NSCollectionView 中的选择进入新视图以及如何将选择的图像显示给新的 viewController 类。

我有一个 NSTabView,并且我有 customView,我在其中显示 CollectionView。在 awakeFromNib 我这样做是为了填充我的 collectionView

  -(void)awakeFromNib
{
arrItems = [[NSMutableArray alloc]init];
 NSMutableArray *imageArray=[[NSMutableArray alloc]initWithObjects:@"Baby-Girl-Wallpaper-2012-7.jpg",@"Cute-Little-Baby-Girl.jpg",@"Joker_HD_Wallpaper_by_RiddleMeThisJoker.jpg",@"The-Dark-Angel-Wallpaper-HD.jpg",@"hd-wallpapers-1080p_hdwallpapersarena_dot_com.jpg",@"lion_hd_wallpaper.jpg",@"Ganesh_painting.jpg",@"krishna-wallpaper.jpg",@"LeoN_userpic_79630_fire_lion_by_alex_barrera.jpg",@"273483.png",@"japan_digital_nature-wide.jpg", nil];
NSMutableArray *imageName = [[NSMutableArray alloc]initWithObjects:@"Baby-Girl",@"Cute-Little",@"Joker",@"The-Dark",@"hd-wallpapers", @"lion", @"Ganesh", @"krishna", @"LeoN_userpic",@"273483.png",@"japan_digital", nil];

for(int i = 0; i<[imageArray count]; i++)
{
    STImageCollectionModal * img1 = [[STImageCollectionModal alloc] init];
    img1.image = [NSImage imageNamed:[imageArray objectAtIndex:i]];
    img1.imageName = [NSString stringWithFormat:@"%@",[imageName objectAtIndex:i]];
    [arrItems addObject:img1];
}
[collectionView setContent:arrItems];
}

后来我创建了一个名为“STCollectionView”的NSCollectionView子类的新类,并将collectionView类分配给“STCollectionView”,并在setSelectionIndexes方法的帮助下,我尝试通过这个获取所选项目的索引

  - (void)setSelectionIndexes:(NSIndexSet *)indexes
 NSLog(@"%ld",[indexes firstIndex]);

但是这个方法被调用了两次,每当我输入“super setSelectionIndexes”时,它都会给我垃圾值。我正在搜索它,但找不到任何解决方案。请帮忙..

先感谢您。

4

1 回答 1

-2

你的问题让我很困惑。我在想你可以通过添加 UICollectionView 和UICollectionView添加自定义来完成这项任务UICollectionViewCell。在自定义 UICollectionViewCell 中添加UIImageViewUILabel。在方法中

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"ReuseID";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.imageView.image = [UIImage imagewithNmaed:@"your Image name"];
    cell.label.text = @"image Named";
return cell;
  }

并在 storyBoard 中按住 CLT+拖动到您UIViewController的 .In 方法 prepareForSgue 方法中将数据传递给您的 Next viewController。

于 2013-04-25T12:19:58.433 回答