如何将带参数的块传递给方法

时间:2013-02-20 12:57:18

标签: iphone ios facebook objective-c-blocks

如何将typedef void传递给方法

我有一个typedef

typedef void (^FBLoginHandler)(id <FaceBook>,bool,NSError *error);

FBLoginHandler testHandler;

^(id<FBLoginHandler>, bool, NSError *)error

[login log:@"AccessToken" handler:^(id<FBLoginHandler>, bool, NSError *)error];

任何人都可以建议我如何将typedef值传递给方法

 [login log:@"AccessToken" handler:???];

1 个答案:

答案 0 :(得分:2)

[login log:@"AccessToken" handler:^(id<FaceBook> object, bool trueOrFalse, NSError *error){
    // ... do whatever you'd like to do here.
}];

...或

void ^(handlerBlock)(id<FaceBook>, bool, NSError *) = ^(id<FaceBook> object, bool trueOrFalse, NSError *error) {
    // ... do whatever you'd like to do here
};

[login log:@"AccessToken" handler:handlerBlock];

...或

[login log:@"AccessToken" handler:nil];