Reputation: 661
I am new to OS X and have started dealing with NSCollectionView. What I am trying to do is to take show NSCollectionView with array of imageView an labels. And on the selection of the image I want to open a new viewController class. I am able to show array of images and labels in collection view but I am completely lost on how to go to new view with the selection made in NSCollectionView and how to show the image selected to the new viewController class.
I am having an NSTabView and in that I am having customView in which I am showing CollectionView. And in awakeFromNib I am doing this to populate my 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];
}
Later I created a new class named "STCollectionView" subclass of NSCollectionView and assigned the collectionView class to "STCollectionView" and with the help of setSelectionIndexes method I tried getting the index of the selected item by this
- (void)setSelectionIndexes:(NSIndexSet *)indexes
NSLog(@"%ld",[indexes firstIndex]);
But this method is getting called twice and whenever i put "super setSelectionIndexes" it gives me garbage value. I am searching it all over but unable to find any kind of solution. Please help..
Thank you in advance.
Upvotes: 0
Views: 936
Reputation: 728
Your question is confusing me.What i am thinking you can do this task simply by adding UICollectionView and in UICollectionView
add custom UICollectionViewCell
.In custom UICollectionViewCell add UIImageView
and UILabel
.
in the method
- (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;
}
and in storyBoard hold CLT+drag to your UIViewController
.In the method prepareForSgue Method pass data to your Next viewController.
Upvotes: -2