2012-10-25 5 views
0

먼저, 모든 제안을 시도했다고 말하면서 저를 믿으십시오. 그러나 나는 그들을 다시 시도하려고합니다. 그래서 자유롭게 의견을 말하고 응답하십시오.크기를 조정할 수 없습니다 UITableView xcode 4.5.1 IOS 5.0

- (void) viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    CGRect frame = CGRectMake(tblView.frame.origin.x, tblView.frame.origin.y, tblView.frame.size.width, tblView.contentSize.height); 

    [tblView setFrame:frame]; 
    [tblView reloadData]; 

    CGRect contentRect = CGRectZero; 
    for (UIView *view in scrollView.subviews) 
     contentRect = CGRectUnion(contentRect, view.frame); 

    [scrollView setContentSize:contentRect.size]; 

    scrollView.frame = CGRectMake(scrollView.frame.origin.x, scrollView.frame.origin.y, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height); 
} 

내 @interface는 다음과 같습니다 : 현재 내 코드처럼 보이는

나는 위의 tblView에 내 스토리 보드 테이블 뷰를 연결 한
@interface VH_HotelsListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> { 
    IBOutlet UIScrollView *scrollView; 
    IBOutlet UIImageView *imageView; 
    IBOutlet UITableView *tblView; 
    NSMutableArray *hotelArray; 
} 

. 내 테이블 뷰는 데이터베이스에서 런타임에 채워 지므로 문제가 없음을 알고 있습니다.

위에서 볼 수 있듯이 테이블보기의 콘텐츠 크기가 표시되고 프레임을 동일한 높이로 조정하려고합니다. 그 높이로 내 스크롤보기의 크기를 조정하기 때문에 정확하게 콘텐츠 크기를 얻고 있습니다. 불행히도 테이블 뷰에는 아무런 변화가 없습니다. 비록 내가 그것을 설정 한 후에 NSLog(@"Table View Height: %g", tblView.frame.size.height)이더라도, 나는 내용 크기 Table View Height: 3166와 동일한 수를 얻는다. 따라서 작동하는 것처럼 보이지만 실제로 확장하지는 않습니다.

답변

1

글쎄, 답변이 없으므로 프로젝트를 업데이트했습니다. 나는 모두 내 스토리 보드 밖으로 UITableView을 가지고 지금은 단지 코드를 작성했습니다

다음
- (void)viewWillAppear:(BOOL)animated { 
[super viewWillAppear:animated]; 
    tblView = [[UITableView alloc] initWithFrame:CGRectMake(0, 150, 320, 500) style:UITableViewStyleGrouped]; 
    tblView.dataSource = self; 
    tblView.delegate = self; 

    [scrollView addSubview:tblView]; 
} 

viewDidAppear에 :

- (void) viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    CGRect frame = CGRectMake(tblView.frame.origin.x, tblView.frame.origin.y, tblView.frame.size.width, tblView.contentSize.height); 
    tblView.frame = frame; 
    [tblView reloadData]; 
} 

이 작동하는 것 같군.

관련 문제