我在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。我错了..?
答案 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
是一个属性,滚动视图以某种方式显示)