无法调整UITableView xcode 4.5.1 IOS 5.0的大小

无法调整UITableView xcode 4.5.1 IOS 5.0的大小,uitableview,resize,Uitableview,Resize,首先,请相信我,我已经尝试了所有的建议。但是我愿意再试一次,所以请随意评论/回答。当前我的代码如下所示: - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; CGRect frame = CGRectMake(tblView.frame.origin.x, tblView.frame.origin.y, tblView.frame.size.width, tblView.contentS

首先,请相信我,我已经尝试了所有的建议。但是我愿意再试一次,所以请随意评论/回答。当前我的代码如下所示:

- (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 VH_HotelsListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
    IBOutlet UIScrollView *scrollView;
    IBOutlet UIImageView *imageView;
    IBOutlet UITableView *tblView;
    NSMutableArray *hotelArray;
}
@interface VH_HotelListViewController:UIViewController{
IBUIScrollView*滚动视图;
IBUIImageView*imageView;
ibuitableview*tblView;
NSMutableArray*hotelArray;
}
我已经将我的故事板表格视图绑定到上面的TBL视图中。我的表视图是在运行时从数据库填充的,所以我知道那里没有问题


从上面可以看到,我正在获取表视图的内容大小,并尝试将框架调整到相同的高度。不过,我准确地得到了内容大小,因为它将我的滚动视图调整到了该高度。不幸的是,它对表视图没有任何影响。虽然在设置之后,如果我
NSLog(@“表视图高度:%g”,tblView.frame.size.Height)
刚刚设置好,我会得到与内容大小
表视图高度相同的数字:3166
。所以它好像在工作,但实际上并没有扩展它。

我没有得到答案,所以我更新了我的项目。我已经将
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];
}
然后在
视图中显示:

- (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];
}
这似乎奏效了