kolinkrewinkel / KKGridView

Deprecated: Grid view library for iOS.
https://github.com/kolinkrewinkel/KKGridView
Other
821 stars 152 forks source link

Pass indexPath to another view controller #125

Closed TomWol closed 12 years ago

TomWol commented 12 years ago

I am trying to integrate this great gridview with a photoviewer, where after one taps on a cell (which I've adapted to display a thumbnail of an image), a new view controller is pushed with the photoviewer (and the index is passed on).

Now, with the way taps on a cell are detected (with _handleSelection in KKGridView), I'm having trouble achieving this. I have located the part where the proper cell has been identified as this part of that code:

if (state == UIGestureRecognizerStateBegan) {
    [self _highlightItemAtIndexPath:indexPath];
    _selected = YES;

But my question is: how can I, from this point, somehow push a view controller with that indexPath? Obviously I can't do this in this part of the code as there's no navigation controller, but it is the only part of the code where tapping on a cell is accurately detected (other than highlightItemAtIndexPath, but that's in the same class so the problem remains).

I am new to iOS development, so this may be really obvious, but I have been trying this for days. Thank you in advance.

jonsterling commented 12 years ago

Typically, you'd leave KKGridView itself alone, and implement the desired behavior in its delegate (your view controller) according to the <KKGridViewDelegate> profile. Have you tried this? If so, is -[<KKGridViewDelegate> gridView:didSelectItemAtIndexPath:] not working properly for you?

Jon

kolinkrewinkel commented 12 years ago

Yeah, you'd implement the -didSelectItem method, then pass the indexPath with something like...

ItemViewController *itemView = [[ItemViewController alloc] initWithNibName:whateverPeopleWhoUseNibsCallTheirStupidNibs];
itemView.indexPath = indexPath; /* this is passed in the method from KKGridView */
TomWol commented 12 years ago

I figured it was something this easy, just didn't think of it. Works like a charm, thanks to both of you.