用此方法传值可以替代委托了。具体例子
#import<UIKit/UIKit.h>
@interface MainView : UIViewController
{
}
-(IBAction)push:(id)sender;
@end
MainView.m
#import "MainView.h"
#import "SecondView.h"
@implementation MainView
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
}
- (void)didReceiveMemoryWarning
{
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
}
-(IBAction)push:(id)sender
{
}
- (void)viewDidUnload
{
}
- (BOOL)shouldAutorotateToInterf
{
}
@end
Second.h
#import<UIKit/UIKit.h>
typedef void (^MyBlock)(NSString*);
@interface SecondView : UIViewController
{
}
-(IBAction)back:(id)sender;
-(id)initwithBlock:(MyBlock)str;
@end
Second.m
#import "SecondView.h"
@implementation SecondView
-(id)initwithBlock:(MyBlock)str
{
}
-(IBAction)back:(id)sender
{
}
- (void)didReceiveMemoryWarning
{
}
-(void)dealloc{
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
}
- (void)viewDidUnload
{
}
- (BOOL)shouldAutorotateToInterf
{
}
@end