[MonoTouch] Objective-C protocol binding method not invoked
Xy
Xy at pyriformgroup.com
Tue Dec 6 00:23:12 EST 2011
Hi Rolf,
I'm not sure what RespondsToSelector is. Could you explain how to use it?
Rolf Bjarne Kvinge wrote
>
> Hi,
>
> So after having a better look at your code I can't say what's going on,
> but
> maybe you can override RespondsToSelector for that type and see what's
> being answered (and asked)?
>
> Rolf
>
> On Wed, Nov 30, 2011 at 4:41 AM, Xy <Xy@> wrote:
>
>> Hi Rolf,
>>
>> We are using the mentioned doc, as well as the bindings reference guide
>> to
>> create our bindings. Perhaps the original context of this thread was
>> lost,
>> so I'm posting the first message again:
>> ---------------------
>> I bind a protocol that specifies the type for a delegate:
>> [BaseType (typeof (NSObject))]
>> [Model]
>> interface SCTableViewModelDataSource
>> {
>> ........
>>
>> [Export
>> ("tableViewModel:newItemForArrayOfItemsSectionAtIndex:")]
>> NSObject
>> NewItemForArrayOfItemsSectionAtIndex(SCTableViewModel tableViewModel, int
>> index);
>>
>> } // SCTableViewModelDataSource
>>
>> And a class that uses the delegate, as well a few subclasses:
>>
>> [BaseType (typeof (NSObject))]
>> interface SCTableViewModel
>> {
>> ........
>>
>> ///** The object that acts as the data source of
>> 'SCTableViewModel'. The object must adopt the SCTableViewModelDataSource
>> protocol. */
>> //@property (nonatomic, assign) id dataSource;
>> [Export ("dataSource", ArgumentSemantic.Assign),
>> NullAllowed]
>> NSObject WeakDataSource { get; set; }
>>
>> [Wrap ("WeakDataSource"), NullAllowed]
>> SCTableViewModelDataSource DataSource { get; set; }
>> } // SCTableViewModel
>>
>> [BaseType (typeof (SCTableViewModel)), DisableDefaultCtor]
>> interface SCArrayOfItemsModel
>> {
>> ........
>> } // SCArrayOfItemsModel
>>
>> [BaseType (typeof (SCArrayOfItemsModel))]
>> interface SCArrayOfObjectsModel
>> {
>> ........
>> } // SCArrayOfObjectsModel
>>
>> In my view controller, I create an inner class that inherit the protocol:
>> class TableViewModelDataSource :
>> SCTableViewModelDataSource
>> {
>> RootViewController controller;
>>
>> public TableViewModelDataSource
>> (RootViewController
>> controller)
>> {
>> this.controller = controller;
>> }
>>
>> public override NSObject
>> NewItemForArrayOfItemsSectionAtIndex (SCTableViewModel tableViewModel,
>> int
>> index)
>> {
>> Console.WriteLine("Creating new thing");
>> return null;
>> }
>> } // TableViewModelDataSource
>>
>>
>> And I assign a new TableViewModelDataSource object as the DataSource of a
>> SCArrayOfObjectsModel obj:
>>
>> mTableModel = new SCArrayOfObjectsModel();
>> mTableModel.Init();
>> mTableModel.DataSource = new
>> TableViewModelDataSource(this); // this is the vew controller
>>
>> I have tested this same code in an Obj-C iOS project, and the delegate
>> method tableViewModel:newItemForArrayOfItemsSectionAtIndex: gets called
>> when
>> expected. However, I wasn't able to get the C# equivalent invoked. There
>> is
>> no console output, and a breakpoint in the method does not stop
>> execution.
>> Am I somehow not binding the protocol correctly, or am I missing a step
>> in
>> binding?
>> ---------------------
>>
>>
>> Rolf Bjarne Kvinge wrote
>> >
>> > Hi,
>> >
>> > Have you read this:
>> > http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types?
>> If
>> > you just want to provide bindings, having a tool do most of the work is
>> > usually best :)
>> >
>> > Rolf
>> >
>> > On Tue, Nov 29, 2011 at 12:59 AM, Xy <Xy@> wrote:
>> >
>> >> Hi Rolf,
>> >>
>> >> Thanks for the advice, but we're actually not trying to implement this
>> >> Obj-C
>> >> class in C#, just provide C# bindings to its APIs. I looked at more
>> code
>> >> examples, and looks it may not necessary to declare these protocols in
>> C#
>> >> bindings. So we're going back to the original question: what might
>> cause
>> >> a
>> >> delegate method that gets called in an iOS program to not get called
>> in
>> a
>> >> MT
>> >> program with same/similar code logic?
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://monotouch.2284126.n4.nabble.com/Objective-C-protocol-binding-method-not-invoked-tp4105828p4117403.html
>> >> Sent from the MonoTouch mailing list archive at Nabble.com.
>> >> _______________________________________________
>> >> MonoTouch mailing list
>> >> MonoTouch at .ximian
>> >> http://lists.ximian.com/mailman/listinfo/monotouch
>> >>
>> >
>> > _______________________________________________
>> > MonoTouch mailing list
>> > MonoTouch at .ximian
>> > http://lists.ximian.com/mailman/listinfo/monotouch
>> >
>>
>>
>> --
>> View this message in context:
>> http://monotouch.2284126.n4.nabble.com/Objective-C-protocol-binding-method-not-invoked-tp4105828p4121794.html
>> Sent from the MonoTouch mailing list archive at Nabble.com.
>> _______________________________________________
>> MonoTouch mailing list
>> MonoTouch at .ximian
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at .ximian
> http://lists.ximian.com/mailman/listinfo/monotouch
>
--
View this message in context: http://monotouch.2284126.n4.nabble.com/Objective-C-protocol-binding-method-not-invoked-tp4105828p4163528.html
Sent from the MonoTouch mailing list archive at Nabble.com.
More information about the MonoTouch
mailing list