Я искал, без всякого успеха, ответ на этот вопрос. Я создал UITableView, используя стиль Grouped
. Это приложение для iPad для iPad, и мне нужна только таблица слева (в области 0, 300, 20, 748), однако установка tableView.frame = CGRectMake(0, 20, 300, 748)
ничего не делает.Настроить ширину Grouped 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' свойство на ваше представлении таблицы? Посмотрите, на что он по умолчанию. Кроме того, вы можете проверить свойство frame/autoresizingMask на 'ViewController'. Возможно, ваш сложенный вид заполняет рамку ландшафта, и ваш вид таблицы соответствует примеру. – Aaron
Расширяет ли ваш 'ViewController' (плохое имя BTW)' UIViewController' или 'UITableViewController'? – rmaddy
Да, это был класс испытаний, который я только что сделал (отсюда и имя), и спасибо за все быстрые ответы, я разобрал его, хотя спасибо :) – bruceyyy