Using this method to pass a value overrides the delegate. Concrete Example MainView.h
#import <UIKit/UIKit.h>
@interface Mainview:uiviewcontroller
{
Iboutlet uibutton* btn;
Iboutlet uilabel* labshow;
}
-(Ibaction) Push: (ID) sender;
@end
mainview.m
#import "MainView.h"
#import "SecondView.h"
@implementation Mainview
-(ID) Initwithnibname: (nsstring*) Nibnameornil Bundle: (nsbundle*) Nibbundleornil
{
self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil];
if (self) {
}
return self;
}
-(void) didreceivememorywarning
{
[Superdidreceivememorywarning];
}
#pragma mark-view lifecycle
-(void) viewdidload
{
[Superviewdidload];
}
-(Ibaction) Push: (ID) sender
{
Secondview *s =[[secondview alloc] initwithblock:block_copy (^ (NSString *str) {
NSLog (@ "%@", str);
Labshow.text = str;
})];
[Self.navigationcontroller pushviewcontroller:s Animated:yes];
[s release];
}
-(void) viewdidunload
{
[Superviewdidunload];
}
-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation
{
return (interfaceorientation = = uiinterfaceorientationportrait);
}
@end
Second.h
#import <UIKit/UIKit.h>
typedef void (^myblock) (nsstring*);
@interface Secondview:uiviewcontroller
{
Iboutlet Uitextfield*txtview;
Myblock my;
}
-(Ibaction) Back: (ID) sender;
-(ID) Initwithblock: (Myblock) str;
@end
Second.m
#import "SecondView.h"
@implementation Secondview
-(ID) Initwithblock: (myblock) str
{
self = [super init];
if (self)
{
My =str;
}
return self;
}
-(Ibaction) Back: (ID) sender
{
nsstring* s = txtview.text;
if (my)
{
my (s);
}
[Self.navigationControllerpopViewControllerAnimated:YES];
}
-(void) didreceivememorywarning
{
[Superdidreceivememorywarning];
}
-(void) dealloc{
Block_release (my);
[Super Dealloc];
}
#pragma mark-view lifecycle
-(void) viewdidload
{
[Superviewdidload];
}
-(void) viewdidunload
{
[Superviewdidunload];
}
-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation
{
return (interfaceorientation = = uiinterfaceorientationportrait);
}
@end