我在我的应用程序中实现了分割 View 。当我的应用程序启动时,它显示正常。
masterview=左侧 View 和detailView=主视图
但是我的主视图还包含 2 个 TableView 。当我单击 TableView 的任何行时,详细信息 View (现在,类 View )不会显示。
意思是我想根据所选的主视图的表格行显示多个详细信息 View 。
我的分割 View 代码如下:
// 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];
}
}
帮我解决这个问题
最佳答案
有问题的行是 didSelectRowAtIndexPath: 方法中的这一行:
[self.appDelegate.splitViewController viewWillDisappear:YES];
我不知道你为什么把它放进去,但如果你删除它,它应该可以工作。您也不需要这一行:
[self.class_VC viewWillAppear:YES];
虽然重写 viewWillAppear: 和 viewWillDisappear: 很常见,但你几乎从来不会像现在这样调用它们。
关于iphone - ipad 中的 SplitView 导航问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14787318/