I was looking at this question.
One of the answers shows how to use blocks to pass data backwards view the prepareForSegue
method. My understanding is this method should really be used to pass data forward, not backwards.
I'm wanting to try blocks out for this purpose - passing data back to another viewController.
My question is: How do I do this, without using prepareForSegue
method?
I could use for instance in a UITableView - didselectRowAtIndexPath
and dismiss the view - but then how does the receiving view get "notified" there is data to come back, without using a delegate?
sent data backward
declare block
in your secondViewController.h
file
@property (nonatomic, copy)void(^myBlock)(NSString *);
call block wherever you need to pass data from .m file of secondViewController
myBlock(@"this will displayed in firstViewController");
3.import above .h
file in your firstViewController
.m
file
and define your block
as
secondViewController *ref =[[secondViewController alloc ]init];
ref.myBlock =^void(NSString *data)
{
self.labelOffirstviewcontroller=data;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With