2013-05-10 2 views
1

나는이 문제에 대한 해답을 찾지 못했습니다. 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 픽셀이되도록 표의 크기를 조정할 수있는 방법을 찾고 있습니다. 이것이 가능한 방법에 대한 제안?

+0

당신이 당신의 테이블보기에서'autoresizingMask' 속성을 확인 했습니까? 그것이 기본값으로 설정되어 있는지 확인하십시오. 또한,'ViewController'에서 frame/autoresizingMask 속성을 검사 할 수도 있습니다. 포함 된 뷰가 가로 프레임을 가득 채우고 테이블 뷰가 적합하다고 볼 수 있습니다. – Aaron

+0

'ViewController' (나쁜 이름 BTW)가'UIViewController' 또는'UITableViewController'를 확장합니까? – rmaddy

+0

네, 그냥 테스트 클래스 (따라서 이름) 및 모든 빠른 답장을 주셔서 감사합니다, 비록 그것을 밖으로 정렬했습니다 :) – bruceyyy

답변

0

ViewControllerUIViewController이라고 가정하면 테이블보기를 기본보기 (사용자의 크기가 조정 됨)로 만드는 대신 표보기를 추가하기 만하면됩니다.

은 교체 :

self.view = tableView; 

로 :

[self.view addSubview:tableView]; 

지금 테이블 뷰는 사용자가 설정 한 프레임을 유지합니다. 당신이 테이블 왼쪽 아래로보기 원하고, 아마도 높이를 채울 수 있기 때문에

, 당신은 정말이 작업을 수행해야합니다

- (void)viewDidLoad { 
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 300, self.view.frame.size.height) style:UITableViewStyleGrouped]; 

    tableView.delegate = self; 
    tableView.dataSource = self; 

    NSArray *first = [NSArray arrayWithObjects:@"first", @"second", @"third", nil]; 
    NSArray *second = [NSArray arrayWithObjects:@"fourth", @"fifth", @"sixth", nil]; 

    self.sections = [NSArray arrayWithObjects:first, second, nil]; 

    tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
    [self.view addSubview:tableView]; 

    [tableView reloadData]; // don't reload until it's added and the data is ready 
} 
+0

답장을 보내 주셔서 감사합니다! 도움 :) – bruceyyy

관련 문제