I'm trying to use a CollectionView as a nice layout for my navigation buttons. I have a big If....else statement but I'm getting the error:
Semantic Issue Property 'indexPath' not found on object of type 'UICollectionViewCell *'
Here is the code that is giving the error. There must be a better way to get the index paths for the cell.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if (_navCell.indexPath = @"0 - 0")
{
[self performSegueWithIdentifier:@"toPersonnel" sender:self];
}
else if (_navCell.indexPath = @"0 - 1")
{
[self performSegueWithIdentifier:@"toEquipment" sender:self];
}
else if (_navCell.indexPath = @"0 - 2")
{
[self performSegueWithIdentifier:@"toTasks" sender:self];
}
else if (_navCell.indexPath = @"0 - 3")
{
[self performSegueWithIdentifier:@"toTriage" sender:self];
}
else if (_navCell.indexPath = @"0 - 4")
{
[self performSegueWithIdentifier:@"toLogs" sender:self];
}
else if (_navCell.indexPath = @"0 - 5")
{
[self performSegueWithIdentifier:@"toMapping" sender:self];
}
else if (_navCell.indexPath = @"0 - 6")
{
[self performSegueWithIdentifier:@"toHeadsUp" sender:self];
}
else if (_navCell.indexPath = @"0 - 7")
{
[self performSegueWithIdentifier:@"toMessenger" sender:self];
}
}
And the other code for my collection view:
@interface mainViewController ()
@property (strong, nonatomic) IBOutlet UICollectionViewCell *navCell;
@end
the viewdidload:
- (void)viewDidLoad
{
[super viewDidLoad];
navItems = [[NSMutableArray alloc]init];
[navItems addObject:@"personnel"];
[navItems addObject:@"equipment"];
[navItems addObject:@"tasks"];
[navItems addObject:@"triage"];
[navItems addObject:@"logs"];
[navItems addObject:@"mapping"];
[navItems addObject:@"headsup"];
[navItems addObject:@"messenger"];
}
Collection view methods
-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [navItems count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIImageView *image = (UIImageView *)[cell viewWithTag:100];
image.image = [UIImage imageNamed:[navItems objectAtIndex:indexPath.row]];
return cell;
}
Could someone show the proper way to find the indexPath of the different cells so I can connect them to my segues?
Thanks
There are many things wrong with your didSelectRow...
method.
indexPath
parameterTry this:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSString *segue = segues[indexPath.row];
[self performSegueWithIdentifier:segue sender:self];
}
Add an instance variable for segues
as NSArray *segues;
.
Then in viewDidLoad
you can initialize it:
segues = @[ @"toPersonnel", @"toEquipment", @"toTasks" /* and the rest */ ];