我搜索了這個問題的答案,但沒有成功。我使用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