Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Need help binding delegate protocol

$
0
0

I'm trying to get a binding for Card.IO working but seem to be stuck in a catch-22. Here's the relevant part of the ApiDefinition.cs:

[MonoTouch.Foundation.Preserve(AllMembers=true)]
[Model, Protocol, BaseType (typeof (NSObject))]
public partial interface CardIOPaymentViewControllerDelegate {

    [Export ("userDidCancelPaymentViewController:")]
    void  UserDidCancelPaymentViewController (CardIOPaymentViewController paymentViewController);

    [Export ("userDidProvideCreditCardInfo:inPaymentViewController:")]
    void UserDidProvideCreditCardInfo (CardIOCreditCardInfo info, CardIOPaymentViewController paymentViewController);
}

[MonoTouch.Foundation.Preserve(AllMembers=true)]
[BaseType (typeof (UINavigationController))]
public partial interface CardIOPaymentViewController { 

    [Export ("initWithPaymentDelegate:")]
    IntPtr Constructor (CardIOPaymentViewControllerDelegate aDelegate);

    [Export ("initWithPaymentDelegate:scanningEnabled:")]
    IntPtr Constructor (CardIOPaymentViewControllerDelegate aDelegate, bool scanningEnabled);  

Here's the problem:

  1. CardIOPaymentViewController expects a CardIOPaymentViewControllerDelegate to be passed to its constructor

  2. So I derive a class like this:

    class CardIODelegate : CardIOPaymentViewControllerDelegate
    {
        public CardIODelegate()
        {
        }
    
  3. When I try to instantiate CardIODelegate, I get the following exception:

    Unhandled Exception:
    System.Exception: Could not initialize an instance of the type 'CreditCardEditor.CreditCardDevViewController+CardIODelegate': the native 'init' method returned nil.
    It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.
    at MonoTouch.Foundation.NSObject.InitializeHandle (IntPtr handle, System.String initSelector) [0x00094] in /Developer/MonoTouch/Source/maccore/src/Foundation/NSObject2.cs:325 
    
  4. So I figured I'd just implement the interface ICardIOPaymentViewControllerDelegate, but then of course I can't pass it to the constructor.

  5. So then I tried passing null to the CardIOPaymentViewController's constructor and setting the delegate though the property, but it didn't like the null.

So... I think the clue might be in the exception at step 3 - It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false. But,

  • I don't know if I should be ignoring this condition
  • I'm not sure where ThrowOnInitFailure should be set, before constructing the derived delegate? or can the generate binding do this somehow?

I'm sure I'm missing something as the card.io binding looks fairly basic. Any help appreciated.

Brad


Viewing all articles
Browse latest Browse all 204402

Trending Articles