Ios UITableView未显示在UICollectionView中
我在Ios UITableView未显示在UICollectionView中,ios,uitableview,uicollectionview,uicollectionviewcell,Ios,Uitableview,Uicollectionview,Uicollectionviewcell,我在UICollectionViewCell中有一个UITableView,它可以正确显示我需要的所有信息 但是,我刚刚发现,如果我滚动到第二个单元格(TableView位于)“Before”数据已完全加载,那么TableView将不会显示。显示TableView的唯一方法是使用UIRefreshControl刷新页面 谁能在这个问题上帮助我,谢谢 CollectionView的结构如下所示: _______________ | ----------- | | | | | | |
UICollectionViewCell
中有一个UITableView
,它可以正确显示我需要的所有信息
但是,我刚刚发现,如果我滚动到第二个单元格(TableView位于)“Before”数据已完全加载,那么TableView将不会显示。显示TableView的唯一方法是使用UIRefreshControl
刷新页面
谁能在这个问题上帮助我,谢谢
CollectionView的结构如下所示:
_______________
| ----------- |
| | | |
| | |<|-- cell
| | | |
| | cell 1 | |
| | | |<--iPhone screen
| | | |
| | | |
| | | |
| ----------- |
|_____________|
-----------
| |
| |
| |
| cell 2: |
| Table |
| view |
| |
| |
-----------
您能给我看一下您的tableView数据源方法,特别是numberOfRowsInSection在numberOfRowsInSection中,我返回
self.forecast10Array.count
当您的tableView未显示时,您确定forecast10Array不是空的吗?是的,当我向下滚动到tableView时,我的应用程序仍在获取数据。但是,当它完成加载并且forecast10Array不是空的时候,tableView仍然没有显示。当您的数据源准备好时,您是否在tableView和collectionView上调用了重新加载数据?
- (void)refresh
{
ConteneViewCell *cell = (ConteneViewCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:@"DetailViewCell"
forIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]];
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_after(popTime, backgroundQueue, ^{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSString *forecast10DayUrl = [NSString stringWithFormat:@"/%@/forecast10day/q/%.6f,%.6f.json",
kWundergroundAPIKey,
self.location.coordinate.latitude,
self.location.coordinate.longitude];
[manager GET:[kWundergroundAPIBaseUrl stringByAppendingString:forecast10DayUrl]
parameters:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
NSMutableArray *array = [NSMutableArray array];
for (id response in [responseObject valueForKeyPath:@"forecast.simpleforecast.forecastday"]) {
self.forecast10 = [[Forecast10Day alloc] initWithDictionary:response];
[array addObject:self.forecast10];
}
self.forecast10Array = array;
[cell.tableView reloadData];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
}
];
dispatch_async(dispatch_get_main_queue(), ^{
[self.refreshControl endRefreshing];
});
});
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
static NSString *CellIdentifier = @"OverviewCell";
OverviewCell *cell = (OverviewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
else if (indexPath.row == 1)
{
static NSString *CellIdentifier = @"DetailViewCell";
ConteneViewCell *cell = (ConteneViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ForecastCell";
ForecastCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ForecastCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
Forecast10Day *fore10 = [self.forecast10Array objectAtIndex:indexPath.row];
NSString *day = [NSString stringWithFormat:@"%@", fore10.day ? fore10.day : @""];
NSString *high = [NSString stringWithFormat:@"%@", fore10.highC ? fore10.highC : @""];
NSString *low = [NSString stringWithFormat:@"%@", fore10.lowC ? fore10.lowC : @""];
NSString *icon = [NSString stringWithFormat:@"%@", fore10.iconName ? fore10.iconName : @""];
cell.day.text = day;
cell.dayHigh.text = high;
cell.dayLow.text = low;
return cell;
}