в вашем 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
в вашем 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];
}
}
Сейчас в вашей DetailedViewController.h
#import "MasterViewController.h"
@interface DetailedViewController : UIViewController<CellSelectionDelegate>
{
}
@property(nonatomic,strong)MasterViewController *masterView;
@end
в DetailedViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
//Set master page as the delegate.
masterView.delegate = self;
}
объявляет следующий метод делегата
-(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
}
я думаю, вы должны реализовать [протокол] (https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols .html). – Mahesh
Можете ли вы дать какой-то код. – chimbu
вы хотите вызвать метод 'Подробный_контроллер' из' didSelectRowAtIndexPath' 'MasterViewController', правильно? – Mahesh