我在我的应用中实现了拆分视图。当我的应用程序启动时,它显示正常。
masterview = Leftside view& 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];
}
}
帮助我解决此问题
答案 0 :(得分:1)
违规行是didSelectRowAtIndexPath:方法中的一行:
[self.appDelegate.splitViewController viewWillDisappear:YES];
我不知道你为什么把它放进去,但如果你把它删除,它应该有效。你也不需要这一行:
[self.class_VC viewWillAppear:YES];
虽然覆盖viewWillAppear:和viewWillDisappear:是很常见的,但你几乎从来没有像你一样调用它们。