I'm working on a project that requires UIsplitViewController, but I need the rootViewController to be UITabViewController not UITableViewController I'm using storyboard which allows me to display the UITabViewController but when I'm trying to send data to DetailViewControler using delegate DetailViewController not responding, is there any solution for that I've been trying for over 1 month to find a way I can't find anything.
FirstTabViewController *firsTab = [[FirstTabViewController alloc] init];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = [NSArray arrayWithObject:firsTab];
UISplitViewController *splitViewController = (UISplitViewController *) self.window.rootViewController;
tabBar = (UITabBarController *)[splitViewController.viewControllers objectAtIndex:0];
splitViewController.delegate = [splitViewController.viewControllers lastObject];
AppDelegate.m applicationDidFinishLaunch add these lines of codes and return YES
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
TabOneViewController.h add these lines of codes:
#import <UIKit/UIKit.h>
@class DetailViewController;
@interface TabOneViewController : UIViewController
@property (nonatomic, strong) DetailViewController *detailViewController;
- (IBAction)SendData:(id)sender;
@end
TabOneViewController.m add these codes:
#import "DetailViewController.h"
in viewDidLoad add This Line of Code:
- (void)viewDidLoad
{
[super viewDidLoad];
// this code is very very important.
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}
in the button action method add this line of code:
- (IBAction)SendData:(id)sender {
self.detailViewController.detailItem = @"Hello From First Tab";
}
In DetailViewController Do the following: in The .h file add these properties
@property (strong, nonatomic) id detailItem;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
in the .m file add the following
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = self.detailItem;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// call the configureView method
[self configureView];
}
now on any additional view added to the Left Panel you have to copy the code written in TabOneController and it should work
Done now it works on any kind of controllers very easy solution took me over a month to solve it hope it helps you guys.