0

我在我的应用程序中实现了拆分视图。当我的应用程序启动时,它显示正常。

masterview=左侧视图 & detailView = 主视图

但我的主视图还包含 2 个表格视图。当我单击表格视图的任何行时,详细视图(现在,类视图)不会显示

意味着我想根据选择的主视图的表行显示多个详细视图。

我的拆分视图代码如下:

// AppDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

LeftViewController *masterViewController = [[LeftViewController alloc] initWithNibName:@"LeftViewController_iPad" bundle:nil] ;
        UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController] ;

        HomeViewController *detailViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];


        masterViewController.home_Detail = detailViewController;

        self.splitViewController = [[UISplitViewController alloc] init] ;
        self.splitViewController.delegate = detailViewController;




        self.splitViewController.viewControllers=[NSArray arrayWithObjects:masterNavigationController,detailNavigationController, nil];

        self.window.rootViewController = self.splitViewController;

        [self.window makeKeyAndVisible];
}



//LeftView.m

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    [self.appDelegate.splitViewController viewWillDisappear:YES];
    NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] viewControllers]];

    [viewControllerArray removeAllObjects];

    if (tableView==tbl_class) 
    {

       self.class_VC=[[Class_Vice_ViewController alloc]initWithNibName:@"Class_Vice_ViewController" bundle:nil];


        [[NSUserDefaults standardUserDefaults]setInteger:[[[classNames objectAtIndex:indexPath.row]valueForKey:@"class_id"]intValue] forKey:@"psel_class"];

        NSLog(@"%d",[[[classNames objectAtIndex:indexPath.row]valueForKey:@"class_id"]intValue]);



        [viewControllerArray addObject:self.class_VC];
        self.appDelegate.splitViewController.delegate = self.class_VC;

        [[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];
        [class_VC viewWillAppear:YES];

    }
}

帮我解决这个问题

4

1 回答 1

1

违规行是 didSelectRowAtIndexPath: 方法中的这一行:

[self.appDelegate.splitViewController viewWillDisappear:YES];

我不知道你为什么把它放进去,但如果你删除它,它应该可以工作。您也不需要这一行:

[self.class_VC viewWillAppear:YES];

虽然重写 viewWillAppear: 和 viewWillDisappear: 是很常见的,但您几乎从不会像现在这样调用它们。

于 2013-02-09T16:59:31.920 回答