Reputation: 806
In my MasterViewController
uitabelview
did select method change the DetailedViewController
view.
My problem is when i change the view in DetailedViewController
need to save the textfield values if user not saved manually.
How can i check this from MasterViewController
or any idea to detect master view did select method called from DetailedViewController
.
thanks in advance.
Upvotes: 0
Views: 403
Reputation: 1167
in your MasterViewController.h
@protocol CellSelectionDelegate <NSObject>
-(void)rowSelected:(NSIndexPath *)indexPath;
@end
@interface MasterViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
}
@property(nonatomic,strong)IBOutlet UITableView *menuTable;
@property (nonatomic, weak) id<CellSelectionDelegate> cellDelegate;
@end
in your MasterViewController.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([self.cellDelegate respondsToSelector:@selector(rowSelected:)])
{
//sending selected indexPath, you can use indexPath.row in your detail view
[self.cellDelegate rowSelected:indexPath];
}
}
Now in your DetailedViewController.h
#import "MasterViewController.h"
@interface DetailedViewController : UIViewController<CellSelectionDelegate>
{
}
@property(nonatomic,strong)MasterViewController *masterView;
@end
in DetailedViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
//Set master page as the delegate.
masterView.delegate = self;
}
Now declare following delegate method
-(void)rowSelected:(NSIndexPath *)indexPath
{
NSLog(@"Your selected Row : %d",indexPath.row);
//do your work according to selection made in master view. use indexpath.row to identify which option was selected, you can also pass the other data with rowselected: method
}
Upvotes: 1