Programmatically create a UIView for UITabBarController
Hi i have a UITabBarController with 5 tabBar items. The forth is UIScrollView.
The area that presented by the forth tab i wont to have specific height.
so till here i've done this
This is were i create my UITabBarController.(aViewController.h)
@interface aViewController: UIViewController <UITabBarControllerDelegate>{
UITabBarController *newTabBarController;
UIView *myView;
}
aViewController.m
- (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 = contro开发者_如何转开发llers; //this is the line that a get an error :Tread1:Program receive signal: SIGABRT
[myView release];
}
if i make a viewController subclass of UIViewController with Xcode and put it in the NSArray there is no problem but i want my view has screen.height - tabbar.height so i tryed make one programmatically. Any help apresiated!
- List item
UIView size
You can do this via Interface Builder.
Create the View you want for a given tab. Then go into the Attribute Inspector. The tab named "simulated metric" allow you to setup a TabBar (and even a NavigationBar).
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
This property is called viewControllers, not views.
The NSArray must contain UIViewController instances, or subclasses.
Thus, it better to define your View with IB (and configure look and feel to display TabBar, etc). Then create your UIViewController with the method initWithNibName:bundle:, and put these instance into the newTabBarController.viewControllers.
Hope it helps
精彩评论