What is the best way to pass data from a child modal view to the parent view controller?
I have a Child Modal Login Screen on my iPad app that I want to pass back user i
You can get it by using Protocol, it is Best way.
I will give you the Basic Idea for how to create a Protocol
Also, read this question: How do I create delegates in Objective-C?
Following code give you the basic idea for Protocol, here in below code you can get Button title from MasterViewController to DetailViewController.
#DetailViewController.h
#import
@protocol MasterDelegate
-(void) getButtonTitile:(NSString *)btnTitle;
@end
@interface DetailViewController : MasterViewController
@property (nonatomic, assign) id customDelegate;
#DetailViewController.m
if([self.customDelegate respondsToSelector:@selector(getButtonTitile:)])
{
[self.customDelegate getButtonTitile:button.currentTitle];
}
#MasterViewController.m
create obj of DetailViewController
DetailViewController *obj = [[DetailViewController alloc] init];
obj.customDelegate = self;
[self.navigationController pushViewController:reportTypeVC animated:YES];
and add delegate method in MasterViewController.m for get button title.
#pragma mark -
#pragma mark - Custom Delegate Method
-(void) getButtonTitile:(NSString *)btnTitle;
{
NSLog(@"%@", btnTitle);
}