【发布时间】:2012-01-03 03:34:54
【问题描述】:
在处理了这个issue 这么多小时而没有任何运气之后,我正在尝试不同的方法,方法是在我的UIViewController 的loadView 中以编程方式创建视图。我的UIViewController 中有UIToolbar 和UITableView,但是在将视图添加为另一个UIView 的子视图时,我在调整大小时遇到了问题。这是我到目前为止得到的:
在我的自定义 UIViewController' loadView 中:
{
[super loadView];
//this doesn't seem right!?!?
self.view.frame = CGRectMake(0, 0, 400, 300);
//create the Tool Bar
self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 45.01)];
[self.toolbar setBarStyle:UIBarStyleDefault];
[self.toolbar setAutoresizesSubviews:TRUE];
[self.toolbar setAutoresizingMask:(UIViewAutoresizingFlexibleWidth)];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:1];
//create buttons
UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
//add buttons to the toolbar
[self.toolbar setItems:buttons animated:NO];
//add toolbar to the view
[self.view addSubview:self.toolbar];
//create UITableView
//a better way setting to set the frame!?!?
UITableView* listTable = [[UITableView alloc] initWithFrame:CGRectMake(0,
self.toolbar.bounds.size.height,
self.view.bounds.size.width,
self.view.bounds.size.height - self.toolbar.bounds.size.height)
style:UITableViewStylePlain];
[listTable setAutoresizesSubviews:TRUE];
[listTable setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight)];
[listTable setDataSource:self];
[listTable setDelegate:self];
self.table = listTable;
[self.view addSubview:listTable];
}
在rootViewController的loadView()中:
{
[super loadView];
controller = [[CustomViewController alloc] init];
[self.customView addSubview:controller.view];
[controller.view setAutoresizesSubviews:TRUE];
}
您可以在此处查看屏幕截图: https://plus.google.com/u/0/photos/112841433450419935389/albums/5693241484889252817/5693241483569881554
我是新手,除了尺寸正确之外,我是否走在正确的轨道上?
非常感谢。
编辑:
我正在尝试创建这样的视图
- UIViewController
- UINavigationBar
- UIView
- UIView
除了我将有两个 UITableView 并且没有分段按钮之外,这与我想要做的很接近。 https://plus.google.com/u/0/photos/112841433450419935389/albums/5693241484889252817/5693260341279558818
【问题讨论】:
标签: objective-c ios uitableview uiviewcontroller