UITableViewCells没有出现在iPhone 5S上的iOS 7.1.2中

时间:2014-09-11 16:15:07

标签: ios objective-c iphone uitableview

据我所知,我遇到的一系列问题只出现在iOS 7.1.2中;虽然我不确定它是否出现在早期版本中。在iOS 7上,我相信它很好,并且在模拟器上。

编辑**进一步说明**

在iOS 7.1.2上,它适用于iPhone 5但不适用于iPhone 5S

当我在设备上运行时,而不是在模拟器中运行。出现第一个单元格,但不显示后续单元格。登录dequeue方法显示该单元格已实例化并出列。此外,除了在单元格中滚动外,第一个单元格对UI完全没有响应。当我将单元格向上拖动到顶部时,它会一直显示到表格视图的顶部,然后完全消失。当我向下拖动单元格时,一切正常。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if(indexPath.row==0)
{
    [self.restaurant sortRewards];
    HeaderCell *headerCell = (HeaderCell *)[tableView dequeueReusableCellWithIdentifier:@"HeaderCell" forIndexPath:indexPath];
    //set up the labels to be loaded from restaurant
    headerCell.restaurantName.text=self.restaurant.name;
    headerCell.restaurantType.text=self.restaurant.placeType;
    headerCell.restaurantDetails.text=[self.restaurant getFormattedDetails];
    headerCell.priceRating.text = [self.restaurant getPriceRatingString];
    headerCell.address.text=self.restaurant.address;
    headerCell.cityStateZip.text=[self.restaurant getCityStateZipString];
    headerCell.phoneNumber.text=[self.restaurant phoneNumber];
    headerCell.description.text=self.restaurant.restaurantDescription;
    //set up the top most image from the header property of the restaurant
    if([self.restaurant isHeaderLoaded]==YES)
    {
        headerCell.restaurantHeader.image=self.restaurant.header;
        NSLog(@"Apparently the image loaded");
    }else
    {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ // 1
            NSData *data = [NSData dataWithContentsOfURL:[self.restaurant headerURL]];
            UIImage *img = [[UIImage alloc] initWithData:data];
            dispatch_async(dispatch_get_main_queue(), ^(void) {
                self.restaurant.header=img;
                self.restaurant.isHeaderLoaded=YES;
                headerCell.restaurantHeader.image=img;
            });
        });
    }
    //load the correct badge for wireless or not
    //as well as the correct use woblet now button
    UIImage* image;
    if(self.restaurant.isSitDown)
    {
       image = [UIImage imageNamed:@"ico_wireless-1"];
        [headerCell.useWobletNow setBackgroundImage:[UIImage imageNamed:@"Use Woblet Button Wireless"] forState:UIControlStateNormal];
    }
    else
    {
        [headerCell.useWobletNow setBackgroundImage:[UIImage imageNamed:@"Use Woblet Button QR"] forState:UIControlStateNormal];
        image = [UIImage imageNamed:@"ico_qr_code-1"];
    }
    headerCell.isSitdownBadge.image=image;
    //set up the map
    [headerCell.map setCenterCoordinate:[self.restaurant.location coordinate] animated:YES];
    //set a pin on the map
    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
    [annotation setCoordinate:[self.restaurant.location coordinate]];
    [headerCell.map addAnnotation:annotation];
    //zoom that motherfucker in
    [self zoomMapViewToFitAnnotations:headerCell.map animated:NO];
    //set up the points circle
    UIImageView *view = [[UIImageView alloc] init];
    view.frame=CGRectMake(0, 0, headerCell.pointsImage.frame.size.height, headerCell.pointsImage.frame.size.height);
    int percent = [self.restaurant.numberOfPoints intValue]%[[(Reward *)[self.restaurant.rewards objectAtIndex:[self.restaurant.rewards count]-1] pointsRequired] intValue];
    percent = 100*percent/[[(Reward *)[self.restaurant.rewards objectAtIndex:[self.restaurant.rewards count]-1] pointsRequired] intValue];
    [view applyCircleWithPercentage:percent andText:[NSString stringWithFormat:@"%@",[self.restaurant.numberOfPoints stringValue]] andTintColor:[UIColor colorWithRed:5.0f/255.0f green:98.0f/255.0f blue:238.0f/255.0f alpha:1.0f]];
    //set the blue swirl
    [headerCell.pointsImage addSubview:view];
    //set the number of points until the next reward

    headerCell.pointsUntilNextReward.text = [NSString stringWithFormat:@"%d pts",[self.restaurant pointsUntilNextReward]];
    //assign our return cell to header cell

    return headerCell;

}
else
{
    //instantiate a RewardCell to reassign to cell at a later point
    RewardCell *rewardCell;
    //pull the appropriate reward from the restaurant
    Reward *reward = [[self.restaurant rewards] objectAtIndex:indexPath.row-1];
    if([reward.pointsRequired intValue]<=[self.restaurant.numberOfPoints intValue])
    {
        //if you have more points that the points required for a given reward dequeue with the identifier reward cell on in order to use the appropriate UI.
        rewardCell = (RewardCell *)[tableView dequeueReusableCellWithIdentifier:@"RewardCellOn" forIndexPath:indexPath];
    }
    else
    {
        //otherwise you need to use the UI for when you don't have enough points.
        rewardCell = (RewardCell *)[tableView dequeueReusableCellWithIdentifier:@"RewardCellOff" forIndexPath:indexPath];
    }
    //number of points you need to use a given reward need to be set
    rewardCell.numberOfPointsRequired.text = [NSString stringWithFormat:@"%@ pts",reward.pointsRequired];
    //the description needs to be set on the cell
    rewardCell.rewardDescription.text=reward.rewardDescription;
    //the cell needs to be assigned to our rewardCell that we instantiated and dequeued at the beginning on the if
    return rewardCell;
}
return cell;
}

编辑: 对不起,在我的沮丧中,我误读了一些事情。它适用于7.1.2的手机之一和7.1.2的另一部手机。我将看看差异。

编辑2: 我发现了问题,它是在一段我没有包含的代码中:

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row==0)
        return 436;
    return 55;
}

1 个答案:

答案 0 :(得分:1)

这里的问题在于我声明具有与64位体系结构冲突的不正确返回类型的方法:

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

这会返回一个浮点数。一切看起来都很糟糕,但在64位架构中,这会失败,因为返回类型实际上是CGFloat,它是一个可以返回double或float的宏。因此,在非64位架构中,从float到CGFloat的转换很好,因为在32位架构中CGFloat是一个浮点数。在64位架构中,CGFloat是双倍的;然而。

更改此位可修复之前出现的神秘错误。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath