ios - 在 Xamarin 中绑定(bind) Block 的方法
<p><p>我正在尝试在 Xamarin iOS 中为此添加绑定(bind)。如何在 Xamarin 中转换它?</p>
<pre><code>(void)orderingTiles
{
[self traverseTilesWithBlock:^(UIImageView *tileImageView, int i, int j)
{
;
}];
}
(void)traverseTilesWithBlock:(void (^)(UIImageView *tileImageView, int i, int j))block
{
for (int j = 1; j <= self.board.size; j++) {
for (int i = 1; i <= self.board.size; i++) {
NSNumber *value = ;
if ( == 0) continue;
UIImageView *tileImageView = -1];
block(tileImageView, i, j);
}
}
}
</code></pre>
<p>谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我假设您正在创建 <a href="http://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/binding_objc_libs/" rel="noreferrer noopener nofollow">iOS binding library</a> .</p>
<p>首先,你必须声明一个与区 block 匹配的委托(delegate)</p>
<pre><code>// This declares the callback signature for the block:
delegate void TraverseBlock (UIImageView *tileImageView, int i, int j)
// Later, inside your definition, do this:
void TraverseTilesWithBlock (TraverseBlock block);
</code></pre>
<p>要调用它,您可以使用方法或 lambda:</p>
<pre><code>foo.TraverseTilesWithBlock (MyTraverseFunc);
[...]
void MyTraverseFunc (UIImageView tileImageView, int i, int j)
{
// do something
}
</code></pre>
<p>或者使用 lambda:</p>
<pre><code>foo.TraverseTilesWithBlock ((tileImageView, i, j) => {
// do something
});
</code></pre></p>
<p style="font-size: 20px;">关于ios - 在 Xamarin 中绑定(bind) Block 的方法,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34237274/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34237274/
</a>
</p>
页:
[1]