1. 程式人生 > >ios 多個引數的block

ios 多個引數的block

多個引數的block

firstPageViewController.m

1. 在第一個頁面初始化頁面時申明block函式
 _pickerViewController = [[TFPickerViewController alloc]init];
 [_pickerViewController loadTFBlock:^(NSString *parameter1, NSString *parameter2)
 {
          CHDebugLog(@"block Test success data:%@---%@",parameter1,parameter2);
  }];

#pragma mark -- Clicked

- (void)commitClick
{
    [self.navigationController pushViewController:_pickerViewController animated:YES];
}



2. 在第二個頁面對於block定義,設定回撥條件。
當選擇完畢picker view完畢後,獲取到picker view資料後,回傳到第一個頁面去。

TFPickerViewController.h

typedef void (^testTFBlockParameter)(NSString *parameter1 , NSString *parameter2);

@interface TFPickerViewController : baseViewController

@property(nonatomic, weak)testTFBlockParameter blockParameter;

- (void)loadTFBlock:(testTFBlockParameter)block;

@end 


TFPickerViewController.m

- (void)onSelectDataStr:(NSString*)selectStr
{
    CHDebugLog(@"----%@",selectStr);
    
    if (self.blockParameter != nil)
    {
        self.blockParameter(selectStr,@"test Success");
    }
}

#pragma mark -- test more parameter Block

- (void)loadTFBlock:(testTFBlockParameter)block
{
    self.blockParameter = block;
}