0

I'm trying to change the code I had on a Table View Controller to a Collection View Controller, right now I'm trying to get the Segue to work but I get this error:

No visible @interface for 'UICollectionView' declares the selector 'indexPathForSelectedRow'

This is my Segue:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ( [segue.identifier isEqualToString:@"showUpcomingRelease"]){
        UpcomingReleaseViewController *upcomingReleaseViewController = (UpcomingReleaseViewController *)[segue destinationViewController];
        upcomingReleaseViewController.singleRelease = [self.upcomingReleases objectAtIndex:[[self.collectionView indexPathForSelectedRow] row]];
    }
}

Thanks.

4

3 回答 3

6
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showUpcomingRelease"])
    {
        NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
        UpcomingReleaseViewController *upcomingReleaseViewController = [segue destinationViewController];
        upcomingReleaseViewController.singleRelease = self.upcomingReleases[selectedIndexPath.row];
    }
}
于 2013-09-05T22:22:37.320 回答
2

Just use indexPathsForSelectedItems in place of indexPathsForSelectedRow.
But this instruction will return more than one indexPath if you select more than one item. You should restrict the selection to one item by setting the allowsMultipleSelection of the UICollectionView to NO.

That said, Xcode has a brilliant autocompletion feature, you could have started to type "index" and it would have shown indexPathsForSelectedItems directly, you can also refer to the excellent documentation provided with Xcode. I Hope it will help you!

于 2013-09-05T22:11:57.577 回答
-2

From documentation, 2sec google research :

– indexPathsForSelectedItems
于 2013-09-05T21:57:00.267 回答