我正在尝试在 Xamarin iOS 中为此添加绑定(bind)。如何在 Xamarin 中转换它?
(void)orderingTiles
{
[self traverseTilesWithBlock:^(UIImageView *tileImageView, int i, int j)
{
[self bringSubviewToFront:tileImageView];
}];
}
(void)traverseTilesWithBlockvoid (^)(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 = [self.board tileAtCoordinate:CGPointMake(i, j)];
if ([value intValue] == 0) continue;
UIImageView *tileImageView = [self.tiles objectAtIndex:[value intValue]-1];
block(tileImageView, i, j);
}
}
}
谢谢。
我假设您正在创建 iOS binding library .
首先,你必须声明一个与区 block 匹配的委托(delegate)
// This declares the callback signature for the block:
delegate void TraverseBlock (UIImageView *tileImageView, int i, int j)
// Later, inside your definition, do this:
[Export ("traverseTilesWithBlock:")]
void TraverseTilesWithBlock (TraverseBlock block);
要调用它,您可以使用方法或 lambda:
foo.TraverseTilesWithBlock (MyTraverseFunc);
[...]
void MyTraverseFunc (UIImageView tileImageView, int i, int j)
{
// do something
}
或者使用 lambda:
foo.TraverseTilesWithBlock ((tileImageView, i, j) => {
// do something
});
关于ios - 在 Xamarin 中绑定(bind) Block 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34237274/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |