CollectionView里面的TableView是在滚动后设置框架吗?

时间:2014-08-12 06:49:56

标签: ios uitableview uicollectionview

我在UITableView内使用UICollectionViewCell。我想要显示的是tableView的动态高度,具体取决于UITableView中的单元格。但是它的框架是在滚动UICollectionView之后设置的。这是我尝试的代码。

#Pragma mark-CollectionView Methods 
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [_collectionViewLabelArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

UICollectionViewCell *myCell=[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UITableView *tableView=(UITableView*)[myCell viewWithTag:11];
tableView.delegate=self;
tableView.dataSource=self;
[tableView reloadData];
tableView.frame=CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width,tableView.contentSize.height);
    return myCell;
}
 -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{


return CGSizeMake(950, [_tableViewDataArray count]*44);
}
#pragma mark-TableView Methods
 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_tableViewDataArray count];
 }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *myCell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];


myCell.textLabel.text=[_tableViewDataArray objectAtIndex:indexPath.row];
   return myCell;

 }

1 个答案:

答案 0 :(得分:0)

在设置tableView框架后重新加载tableView。

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