我有这段代码,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = indexPath.row;
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
if (row == 0) {
FirstDetailViewController *newDetailViewController = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];
detailViewController = newDetailViewController;
}
if (row == 1) {
SecondDetailViewController *newDetailViewController = [[SecondDetailViewController alloc] initWithNibName:@"SecondDetailView" bundle:nil];
detailViewController = newDetailViewController;
}
if (row == 2) {
view31 *newDetailViewController = [[view31 alloc] initWithNibName:@"view31" bundle:nil];
detailViewController = newDetailViewController;
NSLog(@"%@", detailViewController);
}
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController , detailViewController, nil];
// NSArray *newVCs = [NSArray arrayWithObjects:[self.splitViewController.viewControllers objectAtIndex:0], viewControllers, nil];
NSLog(@"%@", viewControllers);
self.splitViewController.viewControllers = viewControllers;
NSLog(@"%@", self.splitViewController.viewControllers);
[viewControllers release];
// Dismiss the popover if it's present.
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
}
// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (rootPopoverButtonItem != nil) {
[detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}
[detailViewController release];
}
为什么self.splitViewController.viewControllers = viewControllers;
会返回null?
答案 0 :(得分:0)
尝试将detailViewController的值添加到viewControllers时检查它的值。
答案 1 :(得分:0)
我面临同样的问题...... 好吧......我认为你没有看到任何viewControllers,因为只有当用户点击rootviewcontroller中的一行时才会调用此方法。只有这样才能将detailviewcontroller分配给数组。
因此,如果点击视图控制器,您将重新分配数组属性。
现在很有意思,因为当我加载该文件时,我也没有将控制器分配给该splitview控制器数组。