是否有一个绑定示例,其中 iOS 将一个块传递给 C#,然后从 c# 调用?
对该场景的唯一引用是在块回调中。 http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c/binding_types_reference_guide#BlockCallback
我们的问题是该块被调用但它似乎丢失了上下文,即:应该具有值的局部变量会丢失值。
以下是伪代码示例,因为代码过于复杂,无法在此处发布:
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
}];
C#
//ApiDefinition.cs
// method within myCSharpbinding class:
void callsome(int value, [BlockCallback] MyBlock block);
public delegate void MyBlock(int val);