我正在开发一个需要UIsplitViewController的项目,但我需要rootViewController是UITabViewController而不是UITableViewController我正在使用storyboard,它允许我显示UITabViewController但是当我尝试使用委托DetailViewController将数据发送到DetailViewControler时没有回应,有没有解决方案,我已经尝试超过1个月找到一种我找不到的方法。
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];
答案 0 :(得分:0)
AppDelegate.m applicationDidFinishLaunch添加这些代码行并返回YES
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
TabOneViewController.h添加以下代码行:
#import <UIKit/UIKit.h>
@class DetailViewController;
@interface TabOneViewController : UIViewController
@property (nonatomic, strong) DetailViewController *detailViewController;
- (IBAction)SendData:(id)sender;
@end
TabOneViewController.m添加以下代码:
#import "DetailViewController.h"
在viewDidLoad中添加以下代码行:
- (void)viewDidLoad
{
[super viewDidLoad];
// this code is very very important.
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}
在按钮操作方法中添加以下代码行:
- (IBAction)SendData:(id)sender {
self.detailViewController.detailItem = @"Hello From First Tab";
}
在DetailViewController中执行以下操作: 在.h文件中添加这些属性
@property (strong, nonatomic) id detailItem;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
<。>在.m文件中添加以下内容
- (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];
}
现在在添加到左面板的任何其他视图中,你必须复制用TabOneController编写的代码,它应该可以工作
现在完成它适用于任何类型的控制器非常简单的解决方案花了我一个多月来解决它希望它可以帮助你们。