UITableView没有显示在UICollectionView中

时间:2014-04-23 10:44:48

标签: ios uitableview uicollectionview uicollectionviewcell

我在UITableView内有一个UICollectionViewCell,它可以正确显示我需要的所有信息。

但是,我发现如果我滚动到第二个单元格(TableView所在的位置)“之前”数据已经完全加载,那么TableView将不会显示。使TableView显示的唯一方法是使用UIRefreshControl刷新页面。

有人可以帮我解决这个问题,谢谢。

CollectionView的结构如下所示:

_______________
| ----------- |
| |         | |
| |         |<|-- cell
| |         | |
| | cell 1  | |
| |         | |<--iPhone screen
| |         | |
| |         | |
| |         | |
| ----------- |
|_____________|
  -----------
  |         |
  |         |
  |         |
  | cell 2: |
  | Table   |
  | view    |
  |         |
  |         |
  -----------

这是代码:

- (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;
}

0 个答案:

没有答案