Xamarin binding to iOS block

Is there a binding pattern in which iOS passes a block to C #, which is later called from C #?

The only link to this script is here in blockcallback. http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c/binding_types_reference_guide#BlockCallback

Our problem is that the block is called, but it seems that it has lost context, that is: local variables that must have values ​​lose their values.

The following is an example in pseudo code, since the code is too complex to fit here:

Objective-c

void somemethod () { 
  int x = 10;
  Myclass *myobj = [[Myclass alloc] init];
  [myCSharpbinding callsome:123 withBlock:^(int val) {
      myobj.prop1 = val; // fails because myobj is null by the time C# calls the block
      // x is also 0 when c# calls the block
  }];

FROM#

//ApiDefinition.cs

// method within myCSharpbinding class:
void callsome(int value, [BlockCallback] MyBlock block);


public delegate void MyBlock(int val);
+4
source share

All Articles