Hi everybody i am using splitviewcontroller in my ipad app where selecting each row in tableview will display new detailviewcontroller and in one of my detailview i am again pushing a new detailview controller(detailview2) and in that class(detailview2) i am defining a protocol and setting it and when the back button is pressed protocol method is getting fired and my rootview (tableview) is implementing that protocol but method is not getting called even after setting the delegate .if i define the same protocol in detailview1 and rootview is implementing then protocol method is not getting called here below i am posting the code .i did not understand why it is happening like that.any suggestions will be a great help. Detailview2.h
@protocol ModalControllerDelegate;
@interface ViewController : UIViewController<UIPopoverControllerDelegate, UISplitViewControllerDelegate>{
}
@property (nonatomic, assign) id <ModalControllerDelegate> delegate;
@end
@protocol ModalControllerDelegate <NSObject>
- (void)modalControllerDidFinish:(ViewController*)modalController;
@end
Detailview2.m
-(void)back {
// Tell the controller to go back
NSLog(@"ghhskfh");
[delegate modalControllerDidFinish:self];
[self.navigationController popViewControllerAnimated:YES];
}
Rootview.h
@interface RootViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource,ModalDelegate,ModalControllerDelegate> {
FirstDetailViewController *firstDetailViewController;
SecondDetailViewController *secondDetailViewController;
MultipleDetailViewsWithNavigatorAppDelegate *appDelegate;
}
@end
Rootview.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title=@"RootView";
self.viewcontroller=[[ViewController alloc]init];
self.viewcontroller.delegate=self;
//[self.tableView setDelegate:self];
//[self.tableView setDataSource:self];
}
#pragma mark -
#pragma mark ModalController delegate
- (void)modalControllerDidFinish:(ViewController *)modalController {
NSLog(@"modalControllerDidFinish");
}
myappdelegate.m(if necessary)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
// Add the split view controller's view to the window and display.
[window addSubview:self.splitViewController.view];
[window makeKeyAndVisible];
return YES;
}
Implement below code into the your App Delegate Method may be Solve your problem.
Please try below code i thinks it’s work for calling the delegates.
EDITED