0

我在 UIViewController 中制作了一个 UIScrollView 。现在我想向它添加一个 UITabBarController 。但是当我这样做时,我看不到添加到它的 TabBarController ..

我写了这段代码

[testscroll setScrollEnabled:YES];
[testscroll setContentSize:CGSizeMake(320,800)];
FirstViewController *first = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
first.title=@"Search";
UserProfile *second=[[UserProfile alloc]initWithNibName:@"UserProfile" bundle:nil];
second.title=@"My Profile";

UserActivities *third=[[UserActivities alloc]initWithNibName:@"UserActivities" bundle:nil];
third.title=@"My Activities";
LogOut *logout=[[LogOut alloc]initWithNibName:@"LogOut" bundle:nil];
logout.title=@"Sign Out";
NSArray *viewArray= [NSArray arrayWithObjects:first,second,third,logout, nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[self presentModalViewController:tabBarController animated:NO];  

我在第五个ViewController 中添加了这个。我可以看到添加了UIScrollView 和一些标签和文本字段,但没有添加TabBarController。我哪里出错了..?

4

1 回答 1

0

据我所知,您正在创建一个标签栏控制器,然后以模态方式呈现它:

NSArray *viewArray= [NSArray arrayWithObjects:first,second,third,logout, nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[self presentModalViewController:tabBarController animated:NO];  

它没有出现,scrollView因为您没有以任何方式“连接”两者。

如果您希望标签栏控制器出现在滚动视图内,请将其作为子视图添加到后者:

[testscroll setScrollEnabled:YES];
[testscroll setContentSize:CGSizeMake(320,800)];
...
[testscroll addSubview:tabBarController.view];

(我假设这tabBarController是一个属性,并且滚动视图以某种方式显示)

于 2012-11-04T09:40:03.853 回答