iphone - ipad 中的 SplitView 导航问题

标签 iphone ios objective-c xcode uisplitviewcontroller

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

ma​​sterview=左侧 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/

相关文章:

ios - 如何通过 UICollectionView 捕捉手势?

ios - 是否有可能在 ios 上获得相机的焦距?

objective-c - 简单的 UIView 动画移动不起作用

ios - 以编程方式在 AVCaptureVideoPreviewLayer 上添加 UIButton

iphone - 当键盘未进行更改时检测 UITextField 内容的更改

ios - 第一个单元格大小错误

ios - 如何从 parse.com 获取推送通知历史记录? (iOS)

ios - 这样会形成保留周期吗?

ios - 运行时自动布局的 UIButton 大小

ios - 我应该使用哪种方法将数据发送到 Apple Watch 并返回?