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?
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/Objective-C-protocol-binding-method-not-invoked-tp4105828p4105828.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch