我試圖加載特定的UITableViewController
作爲UISplitViewController
的細節視圖,當用戶在主視圖中選擇一個單元時;但有一些問題。當我選擇單元格時,它只是顯示一個空表窗口與一個表視圖控制器。UISplitViewController中的UITableViewController
但是,如果我改變應用程序代理只加載UITableView
控制器不使用它工作正常的UISplitViewController
,所以我知道這是用我編寫的UISplitViewController.
視圖層次結構的方式有問題:
UISplitViewController
-->
UINavigationController
--> UITableViewController (DetailViewController)
UINavigationController
--> UIViewController (ColorViewController)
用戶在ColorViewController
選擇小區和應該改變DetailViewController.
我ñAppDelegate.m
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.viewController = [[ViewController alloc] init];
self.window.rootViewController = [self.viewController splitViewController];
[self.window makeKeyAndVisible];
return YES;
}
在ViewController.m
:
- (UIViewController *) splitViewController {
// Create the navigation-run root view
ColorViewController *rootVC = [ColorViewController controller];
UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:rootVC];
// Create the navigation-run detail view
DetailViewController *detailVC = [DetailViewController controller];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detailVC];
// Add both to the split view controller
svc = [[UISplitViewController alloc] init];
svc.viewControllers = [NSArray arrayWithObjects: rootNav, detailNav, nil];
svc.delegate = detailVC;
return svc;
}
在ColorViewController.m
:
@interface ColorViewController : UITableViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *controller = (UIViewController *)self.splitViewController.delegate;
TableViewController *tvc = [[TableViewController alloc] init];
[controller.view addSubview:tvc.view];
}
什麼改變UISplitViewController
中的詳細信息視圖的最好方法?我是否應該像上面那樣將替換視圖添加到UIViewController
或者有更好的方法嗎?也許這是我的問題的原因?
謝謝...我會盡力做到這一點。我認爲這可能有助於解決問題。 – Imme22009