gpt4 book ai didi

ios - 如何在 Split ViewiOS中将不同的 View 加载到详细 View

转载 作者:行者123 更新时间:2023-12-01 18:27:35 25 4
gpt4 key购买 nike

我想知道如何将不同的 View 从 rootview 加载到 detailView 中。

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

if (indexPath.row == 0) {
SecondViewController *svc = [[SecondViewController alloc] init];

//[self.navigationController pushViewController:svc animated:YES];

}


}

最佳答案

splitviewcontroller有一个包含 2 个 View 的数组,一个是 Root View ,另一个是详细 View ,您可以更改此数组中的 View 。如果你分配并初始化一个 View 并用这两个中的任何一个替换它,那么这个 View 将替换 splitviewcontroller 中的当前 View 。 .

使用此代码为 rootview 的不同单元加载不同的 View 。更改 rootview 的 didSelectRowAtIndexPath方法如下:

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

UIViewController *localdetailViewController = nil;

if (indexPath.row==0)
{

DetailViewController *detailView=[[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];

localdetailViewController=detailView;

detailView=nil;

}

if (indexPath.row==1)
{

SecondViewController *secondDetailView=[[SecondViewController alloc] initWithNibName:@"SecondDetailViewController" bundle:nil];

localdetailViewController=secondDetailView;
secondDetailView = nil;
}

UINavigationController *navController=[[UINavigationController alloc] init];

[navController pushViewController:localdetailViewController animated:YES];

YourSplitViewAppDelegate *delegate=[[UIApplication sharedApplication] delegate];

NSArray *viewControllers=[[NSArray alloc] initWithObjects:[delegate.splitViewController.viewControllers objectAtIndex:0],navController,nil];

delegate.splitViewController.viewControllers = viewControllers;

[localdetailViewController release];

[navController release];

}

关于ios - 如何在 Split ViewiOS中将不同的 View 加载到详细 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12016811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com