나는이 문제에 대한 해답을 찾지 못했습니다. 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
'ViewController' (나쁜 이름 BTW)가'UIViewController' 또는'UITableViewController'를 확장합니까? – rmaddy
네, 그냥 테스트 클래스 (따라서 이름) 및 모든 빠른 답장을 주셔서 감사합니다, 비록 그것을 밖으로 정렬했습니다 :) – bruceyyy