gpt4 book ai didi

iphone - UISplitView - 为masterView中的每一行加载不同的detailView

转载 作者:行者123 更新时间:2023-12-03 19:25:41 26 4
gpt4 key购买 nike

我在 iPad 上使用 UISplitViewController 应用程序。第一个任务是以纵向模式显示主视图和细节 View 。我就是这样做的:

// It is possible to keep the Master View in portrait mode
// also. Just pass YES to this method to enable this mode.
- (id) initWithMasterInPortraitMode:(BOOL) masterInPortrait {
self = [super init];
self.keepMasterInPortraitMode = masterInPortrait;
return self;
}

// Thanks to http://intensedebate.com/profiles/fgrios for this code snippet
-(void) viewWillAppear:(BOOL)animated {
NSLog(@"viewWillAppear");
if(keepMasterInPortraitMode == NO) {
return;
}

//check interface orientation at first view and adjust it
//if it is in portrait mode
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
UIViewController* master = [self.viewControllers objectAtIndex:0];
UIViewController* detail = [self.viewControllers objectAtIndex:1];
[self setupPortraitMode:master detail:detail];
}
}

// Thanks to http://intensedebate.com/profiles/fgrios for this code snippet
- (void)setupPortraitMode:(UIViewController*)master detail:(UIViewController*)detail {
//adjust master view
CGRect f = master.view.frame;
f.size.width = 320;
f.size.height = 1024;
f.origin.x = 0;
f.origin.y = 0;

[master.view setFrame:f];

//adjust detail view
f = detail.view.frame;
f.size.width = 448;
f.size.height = 1024;
f.origin.x = 321;
f.origin.y = 0;

[detail.view setFrame:f];
}

我像这样创建 splitView:

MySplitViewController *mySplitViewController = [[MySplitViewController alloc] initWithMasterInPortraitMode:YES];

好的,效果很好,当我以纵向模式启动应用程序时,它会并排显示主视图和详细 View 。

目前一切正常。但我想在主视图中的每个记录(行)的详细 View 中显示不同的 View 。我在 masterView 中的 didSelectRowAtIndexPath 方法如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
FirstDetailViewController *firstDetailView = [[FirstDetailViewController alloc] initWithNibName:@"firstDetailView" bundle:nil];
UINavigationController *firstDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:firstDetailView];
[firstDetailView release];

[self.splitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, firstDetailNavigationController, nil]];
}
else {
SecondDetailViewController *secondDetailView = [[SecondDetailViewController alloc] initWithNibName:@"secondDetailView" bundle:nil];
UINavigationController *secondDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:secondDetailView];
[secondDetailView release];

[self.splitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, secondDetailNavigationController, nil]];
}
}

在第一行或第二行(在 masterView 中)上单击(触摸)后,splitView 仅显示明细 View (整个屏幕),没有 masterView。

如何强制 splitView 在更改 View 、主视图和详细 View 时显示???

感谢您的帮助!

最佳答案

我已经找到解决办法了。在 masterView 中,我创建了 splitViewController 实例并将本地实例分配给该实例:

settingsSplitViewController = (SettingsSplitViewController *)self.splitViewController;

在方法 didSelectRowAtIndexPath 中,我这样做了:

[settingsSplitViewController setupPortraitMode:self.navigationController detail:detailNavigationController];

希望它能帮助其他人解决此类问题。

关于iphone - UISplitView - 为masterView中的每一行加载不同的detailView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3297744/

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