我想知道如何设计我自己的自定义标签,点击后可以在屏幕上显示多个视图
http://tinypic.com/r/2cxtjk7/5
我目前只能找到底部标签栏方法。感谢你的帮助,我还是很新的,所以如果你能详细解释一下会很棒:)
答案 0 :(得分:1)
使用自定义标签显示多个视图
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
{
AccountViewController *accountViewController = [[AccountViewController alloc]
initWithNibName:@"AccountViewController" bundle:nil];
MoreViewController *moreViewController = [[MoreViewController alloc]
initWithNibName:@"MoreViewController" bundle:nil];
BarTabViewController *barTabViewController = [[BarTabViewController alloc]
initWithNibName:@"BarTabViewController" bundle:nil];
LocationsViewController *locationsViewController = [[LocationsViewController alloc]
initWithNibName:@"LocationsViewController" bundle:nil];
self.viewControllers = [NSArray arrayWithObjects:locationsViewController, accountViewController,
barTabViewController, moreViewController, nil];
[self.view addSubview:locationsViewController.view];
self.selectedController = locationsViewController;
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.selectedIndex = 0;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:locationsViewController, accountViewController,
barTabViewController, moreViewController, nil];
self.tabBarController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController pushViewController:delegate.tabBarController animated:YES];
return self;
}
就像我说的,这将正确显示所选控制器,但是当应用程序启动并且我尝试使用标签栏切换视图时,子视图会变为灰色...以下是切换项目的代码:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item == locationsTabBarItem) {
UIViewController *locationsController = [viewControllers objectAtIndex:0];
[self.selectedController.view removeFromSuperview];
[self.view addSubview:locationsController.view];
self.selectedController = locationsController;
}
else if (item == accountsTabBarItem) {
UIViewController *accountsController = [viewControllers objectAtIndex:1];
[self.selectedController.view removeFromSuperview];
[self.view addSubview:accountsController.view];
self.selectedController = accountsController;
}
else if (item == barTabTabBarItem) {
UIViewController *barTabController = [viewControllers objectAtIndex:2];
[self.selectedController.view removeFromSuperview];
[self.view addSubview:barTabController.view];
self.selectedController = barTabController;
}
else {
UIViewController *moreController = [viewControllers objectAtIndex:3];
[self.selectedController.view removeFromSuperview];
[self.view addSubview:moreController.view];
self.selectedController = moreController;
}
}
答案 1 :(得分:0)
我在视图中添加了最终加载的内容:
PatientDetailsViewController * patientDetailsView = [[PatientDetailsViewController alloc] initWithNibName:@“PatientDetailsViewController”bundle:nil]; [self addChildViewController:patientDetailsView]; [self.patientDetailsView addSubview:patientDetailsView.view]; [self.patientDetailsView setClipsToBounds:YES];
然后通过动画调整视图框大小,使用按钮为其打开动画。