以编程方式为UIAbbarController创建UIView

以编程方式为UIAbbarController创建UIView,uiview,uitabbarcontroller,Uiview,Uitabbarcontroller,嗨,我有一个带有5个选项卡项的UITABBARC控制器。 第四个是UIScrollView 第四个选项卡显示的区域我不希望有特定的高度 所以在这之前我已经做到了 这是我创建UITabBarController的地方。(aViewController.h) 如果我使用Xcode创建UIViewController的viewController子类并将其放入NSArray中,没有问题,但我希望我的视图具有screen.height-tabbar.height,因此我尝试通过编程创建一个。 需要任何帮

嗨,我有一个带有5个选项卡项的UITABBARC控制器。 第四个是UIScrollView

第四个选项卡显示的区域我不希望有特定的高度

所以在这之前我已经做到了

这是我创建UITabBarController的地方。(aViewController.h)

如果我使用Xcode创建UIViewController的viewController子类并将其放入NSArray中,没有问题,但我希望我的视图具有screen.height-tabbar.height,因此我尝试通过编程创建一个。 需要任何帮助

  • 列表项
UIView大小

您可以通过Interface Builder执行此操作

为给定选项卡创建所需的视图。然后进入属性检查器。名为“SimulatedMetric”的选项卡允许您设置选项卡栏(甚至导航栏)

  • SIGABRT

    myView = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,self.view.frame.size.height - newTabBarController.tabBar.frame.size.height)];
    NSArray *controllers = [NSArray arrayWithObjects:myView, nil];
    newTabBarController.viewControllers = controllers; //this is the line that a get an error :Tread1:Program receive signal: SIGABRT
    
此属性称为ViewController,而不是views

NSArray必须包含UIViewController实例或子类

因此,最好使用IB定义视图(并将外观配置为显示TabBar等)。 然后使用initWithNibName:bundle:方法创建UIViewController,并将这些实例放入newTabBarController.viewController中


希望对您有所帮助

谢谢您的回答@NoTTC!我试过了,你的方法很好!因此,在你回答我的问题之前,我做了一些其他的事情。我已经创建了UIViewController的子类,并在viewDidLoad中设置了它的边界!这对我很有用!但再次感谢您的时间!
- (void) viewDidLoad{
newTabBarController = [[UITabBarController alloc]init];
newTabBarController.delegate = self;

myView = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,self.view.frame.size.height - newTabBarController.tabBar.frame.size.height)];
NSArray *controllers = [NSArray arrayWithObjects:myView, nil];
newTabBarController.viewControllers = controllers; //this is the line that a get an error :Tread1:Program receive signal: SIGABRT
[myView release];
}
myView = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,self.view.frame.size.height - newTabBarController.tabBar.frame.size.height)];
NSArray *controllers = [NSArray arrayWithObjects:myView, nil];
newTabBarController.viewControllers = controllers; //this is the line that a get an error :Tread1:Program receive signal: SIGABRT