我搜索了这个问题的答案,但没有成功。我使用Grouped
风格创建了一个UITableView。这是一款适用于iPad的风景应用程序,我只想要左侧的桌子(在区域0,300,20,748),但是设置tableView.frame = CGRectMake(0, 20, 300, 748)
什么也不做。调整分组UITableView的宽度
#import "ViewController.h"
@interface ViewController()
@property (strong, nonatomic) NSArray *sections;
@end
@implementation ViewController
@synthesize sections = _sections;
- (void)viewDidLoad
{
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 300, 748) style:UITableViewStyleGrouped];
tableView.frame = CGRectMake(0, 20, 300, 748);
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
NSArray *first = [NSArray arrayWithObjects:@"first", @"second", @"third", nil];
NSArray *second = [NSArray arrayWithObjects:@"fourth", @"fifth", @"sixth", nil];
self.sections = [NSArray arrayWithObjects:first, second, nil];
self.view = tableView;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.sections count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.sections objectAtIndex:section] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyReuseIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
cell.textLabel.text = [[self.sections objectAtIndex:[indexPath section]]objectAtIndex:[indexPath row]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
tableView.frame = CGRectMake(0, 20, 300, 748);
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我正在寻找一种方法来调整表的大小,使它只有300像素宽,左边。有关这可能性的任何建议?
你检查你的表视图的'autoresizingMask'财产?看看它默认的是什么。另外,你可能想检查'ViewController'上的frame/autoresizingMask属性。您的包含视图可能会填充景观框架,并且您的桌面视图也可能会出现问题。 – Aaron 2013-05-10 22:05:11
你的'ViewController'(坏名BTW)扩展'UIViewController'或'UITableViewController'吗? – rmaddy 2013-05-10 22:07:59
是啊,这是一个测试类,我刚刚(因此得名),并感谢所有的快速回复,我已经整理出来,虽然谢谢:) – bruceyyy 2013-05-10 22:30:32