NSCollectionView:使用Selected Item转到下一个选择视图

时间:2013-04-25 11:13:51

标签: xcode macos nscollectionview

我是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”它给我垃圾值。 我正在搜索它,但无法找到任何解决方案。请帮忙..

提前谢谢。

1 个答案:

答案 0 :(得分:-2)

你的问题令我感到困惑。我想你可以通过添加UICollectionView并在UICollectionView添加自定义UICollectionViewCell来完成此任务。在自定义UICollectionViewCell中添加UIImageView和{{1 }}。 在方法

UILabel

并在storyBoard中按住CLT +拖动到你的- (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; } 。在方法中,prepareForSgue方法将数据传递给你的Next viewController。

相关问题