1. 程式人生 > >iOS delegate 傳值步驟

iOS delegate 傳值步驟

iOS  delegate 傳值步驟

 A.h

@protocol  MyDelegate

- (void )mjFuncWithString:(NSString*)str;

@end

@interface MyViewController : UIViewController

@property (assign) id<MyDelegate> delegate;

@end

A.m

 [self.delegatemjFuncWithString:self.t.text];

B.h

@interface ViewController : UIViewController

<MyDelegate>

B.m

MyViewController * svc=[[MyViewControlleralloc]initWithNibName:@"MyViewController"bundle:[NSBundlemainBundle]];

    svc.delegate=self;

    [selfpresentViewController:svc animated:YEScompletion:nil];

//實現方法

-(void)mjFuncWithString:(NSString*)str{

}