This should be a relatively simple question but I am new to iOS and I want to get started on the right foot.
I have a IGGrid displaying a list of inventory items that I am pulling from azure. THat is all working well. What I want to do is show a details screen when I double tap, or do a slide to show a button to navigation to the details page.
Is there an example or tutorial for how to do this that I missed? Any help would be great.
Thanks in advanced,
Ryan
Hi Ryan
I'd be happy to help.
I probably wouldn't recommend doing a double tap on a row. While it's possible, its not really a common pattern in iOS. Instead, i'd go with your second approach, with the slide to reveal the details.
We actually have a sample in our samples browser that shows how to display a button in the slide out of a row, and to listen to it's click event.
It's actually not much code, so i've put the snippets below:
_gridView.swipeRowAction = IGGridViewSwipeRowActionManualSlideBoth; // You can also do just left or right here. I'd definitely recommend the Manual slide options though, they're more fluid.
_gridView.delegate = self; // Make sure you implement the IGGridViewDelegate protocol, and then listen to the following methods
-(UIView *)gridView:(IGGridView *)gridView viewForSlideRowLeft:(IGRowPath *)path
{
// Store off the row path, so that we can react to it when our button is clicked.
_row = path;
return _slideView;
}
-(UIView *)gridView:(IGGridView *)gridView viewForSlideRowRight:(IGRowPath *)path
In the code above, since i'm using the Both enumeration option, i'm listening to the left and and right, however, feel if you're just listening to left or right, just listen to the one.
Now, i've created my View in advance, so that i can reuse it, since we only allow you to slide a single row at any given time.
And here is my code to create the view thats displayed:
// Create the View that we will display under the row when its slid.
_slideView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
UIButton* button = [UIButton buttonWithType:UIButtonTypeInfoDark];
button.frame = CGRectMake(0, 0, 100, 100);
button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[_slideView addSubview:button];
Now to answer the second part of your question, for displaying a details screen, you have two options. Both require your Details screen to be another UIVIewController.
Your first option, is if you're using a UINavigationViewController. If thats the case, then you can just push your next view onto the stack:
MyDetailsVC* vc = [[MyDetailsVC alloc]init];
[self.navigationController pushViewController:vc animated:YES];
Or if you just want to present your details view controller as a modal view:
[self presentViewController:vc animated:YES completion:nil];
Hope this helps!
-SteveZ
Steve,
That is really helpful. I am working in c# with xamarin and I am not sure how to attach to the Slide Events. I do see the events in the IGGrideView class.
Do you have an example in c#?
Thanks
Rya
Hey Ryan,
Sure thing!
I've attached a sample (in C#) doing the same thing as the code snippets i sent you for Objective-C.
Let me know if you have any questions.
Thank you for this. I was able to get everything working now.
Read through your code, and made the required changes to mine. It worked except for the storyboard was causing my app to crash when I went to the details screen. It said "HW kbd: Failed to set (null) as keyboard focus" in the system log. I copied your storyboard code over and it all works but I really want to understand why so I can avoid these issues in the future.
Here is my code. Thanks again.
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="nD8-mQ-QUL"> <dependencies> <deployment identifier="iOS"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/> </dependencies> <scenes> <!--View Controller--> <scene sceneID="tne-QT-ifu"> <objects> <viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController"> <layoutGuides> <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/> <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/> </layoutGuides> <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> </view> <navigationItem key="navigationItem" id="Nba-0N-0MS"/> </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> </objects> <point key="canvasLocation" x="1027" y="344"/> </scene> <!--Navigation Controller--> <scene sceneID="dfo-Hy-Zct"> <objects> <navigationController automaticallyAdjustsScrollViewInsets="NO" id="nD8-mQ-QUL" sceneMemberID="viewController"> <toolbarItems/> <navigationBar key="navigationBar" contentMode="scaleToFill" id="sdE-gA-WAL"> <rect key="frame" x="0.0" y="0.0" width="320" height="44"/> <autoresizingMask key="autoresizingMask"/> </navigationBar> <nil name="viewControllers"/> <connections> <segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="XhZ-ZK-lwO"/> </connections> </navigationController> <placeholder placeholderIdentifier="IBFirstResponder" id="90e-KI-bht" userLabel="First Responder" sceneMemberID="firstResponder"/> </objects> <point key="canvasLocation" x="215" y="1004"/> </scene> </scenes> </document>
I'm not entirely sure.
My guess is that your storyboard referenced an element in your ViewController that no longer exists, and thats whats causing the crash.
But it's really just a guess.