他classのfunctionをviewを引数で呼び出す(iOS)
■ 他のclassから呼び出す。広告などを使い回すときに使う
■ 呼び出し元class
commonFunctoion.h
-(void)showAd:(UIView *)view;
commonFunction.m
-(void)showAd:(UIView *)view { /** * show ad 引数はUIView */ 処理をかく UIViewはcommonのではなく呼び出し先のview }
■ 呼び出し先class
MainViewController.h
//commonFunctionファイルをimport #import "CommonFunction.h" @interface BrowserViewController : UIViewController { CommonFunction *adview; //変数adviewにCommonFunctionをセット } -(void)showAd; //使うfnction定義 @end
MainViewController.m
[super viewDidLoad]; adview = [[CommonFunction alloc] init]; //adview宣言 [adview showAd:self.view]; //引数にself.view(MainView)で実行