在Uphone中的UIScrollView中添加UITabbarControler?

时间:2012-11-04 07:38:59

标签: iphone objective-c cocoa-touch uiscrollview uitabbarcontroller

我在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和一些标签和textFields已经添加但没有添加TabBarController。我错了..?

1 个答案:

答案 0 :(得分: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是一个属性,滚动视图以某种方式显示)