先看一下 NSArray 是怎么传递 block 参数的

...
@interface NSArray (NSExtendedArray)
…

#if NS_BLOCKS_AVAILABLE
- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);

…
@end

 

对于不需要参数的情况,比如只是想在某个方法结束后调用另一方法

//实现
- (void)endInput:(void (^)())completion
{
    [UIView animateWithDuration:0.25 animations:^{

    } completion:^(BOOL finished) {

        if (completion) {
            completion();
        }
    }];
}

//调用
[instance endInput:^{
    //做点什么
}];

 

相关文章:

  • 2021-11-17
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2018-01-11
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案