Hi,
I'm evaluating the IGGridView. One thing I've tried is to register a persistent gesture recognizer (RegisterGesture()) of type UITapGestureRecognizer to show the value in a UIPopover if a cell has been tapped.
But after tapping on a cell the app closes unexpectedly. Sometime an exception occurs of type NSInvalidArgumentExeption and no action handling code will be executed.
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[__NSCFString target:]: unrecognized selector sent to instance 0x1d5c3630 at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 at TestInfragistics.Application.Main (System.String[] args) [0x00008] in /Users/dmeier/Projects/TestInfragistics/TestInfragistics/Main.cs:16
As attached you can find my evaluating project (without the binaries because they are to big in size).
Hi Danny,
Thanks for the sample!
Basically, Xamarin.iOS has a couple ways of creating gestures, and the way you're using unfortunately isn't compatible for being called by the obj-c runtime. However, its actually quite simple to make that adjustment.
Here's a link that shows they way you need to do it: http://dan.clarke.name/2012/08/using-uigesturerecognizer-in-monotouch/
Also, i've modified your code to this:
public override void InitializeCell(IGGridView gridView, IGGridViewCell cell) { var path = gridView.ResolvePathForCell(cell); if (path.IsFixed == IGGridViewFixedColumnDirection.IGGridViewFixedColumnDirectionNone) { var tapGesture = new UITapGestureRecognizer(this, new MonoTouch.ObjCRuntime.Selector("HandleInput")); //var tapGesture = new UITapGestureRecognizer(HandleInput) { NumberOfTapsRequired = 1}; cell.RegisterGestures(new[] { tapGesture }); } } [Export("HandleInput")] private void HandleInput(UITapGestureRecognizer gestureRecognizer) { var cell = gestureRecognizer.View as IGGridViewCell; var viewController = new UIViewController(); var textField = new UITextField(viewController.View.Bounds) { AutoresizingMask = ~UIViewAutoresizing.None, Text = cell.TextLabel.Text }; viewController.View.AddSubview(textField); var popover = new UIPopoverController(viewController); popover.PresentFromRect(cell.Bounds, cell, UIPopoverArrowDirection.Any, true); }
Hope this helps. Don't hesitate if you have any more questions.
-SteveZ
Steve,
I tried to handle cell input the way you suggest but it is crushing application. Once popover comes up a short delay like half seconds and the whole app is crushing.
Is it still the right way to display popovers on a cell tap?
Thanks
Mark
Works like a charm...thank you very much!