block 做参数

三部分

1,定义函数

 

/* 传出类定义block

 */

//定义block

typedef void (^ItemClickBlock)(NSInteger selectedIndex);

//block 做函数参数

+ (instancetype)navigationViewWithItems:( NSArray <NSString *> * )items itemClick:(ItemClickBlock)itemClick;

 

 

2,实现

#pragma mark - init block 做参数,实现方法, --

+ (instancetype)navigationViewWithItems:(NSArray<NSString *> *)items itemClick:(ItemClickBlock)itemClickBlock{

    WSNavigationView *nav = [[WSNavigationView alloc] init];

    nav.btns = [NSMutableArray arrayWithCapacity:items.count];

    //

    NSLog(@"  navigationViewWithItems 初始化 ----------- ");

    nav.itemClickBlock = itemClickBlock;

    nav.items = items;

    禁用滚动到最顶部的属性

    nav.scrollsToTop = NO;

     NSLog(@"-=====--------==---==== ");

    return nav;

}

 

 

3,调用

 //添加导航view

        typeof(self) __weak weakObj= self;

        //调用 block做参数,方法。  - 传入   意义在于:当点击时,传入信息到此。

        WSNavigationView *view = [WSNavigationView navigationViewWithItems:nil itemClick:^(NSInteger selectedIndex) {

            //实现

            NSLog(@"2- WSContainerController init   实现  传入 点击 %lu ",  selectedIndex);

            //传入 弱引用

          //  [weakObj setSelectedIndex:selectedIndex];

            [self setSelectedIndex:selectedIndex];

        }];

        

//////////////////////////数据库使用

 

 

1,实现

-(void)LoadAllCityWithCompletion:(XNDLoadAreaModelCompletion)completion;

 

 

2,实现

-(void)LoadAllCityWithPid:(int)pid Completion:(XNDLoadAreaModelCompletion)completion{

    [[[DBManager alloc]init] loadCityArrayAllWithPid:pid Completion:^(NSArray *messages, NSError *error) {

        self.modelCityArry=[[NSMutableArray alloc]initWithArray: messages ];

        completion(nil,nil);

    }];

}

 

3.调用

  //调用 block做参数的方法 传入

                            [[XNDAreaModule instance] LoadAllCityWithPid:pid Completion:^(NSArray *messages, NSError *error) {

                                if (isPosted==NO) {

                                    [[NSNotificationCenter defaultCenter] postNotificationName:KNotifictionChangeArea object:@"1"];

                                }

                            

                            }];

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值