简体   繁体   中英

UITableView doesn't display the cells in IOS 7

I have this issue when I tried to convert my app from iOS6 to iOS7/iOS8.

UITableView不显示单元格(在iOS6中工作)

UITableView doesn't display the cells (working in iOS6).

I have a similar view that works fine in iOS7 (it doesn't have the UISearchView )

在iOS7中正常工作

I tried several workarounds like clear the background, delete the UISearchBar, etc...

The code is similar in both examples (cells are generated by - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method)

I used the Reveal software to analyze this hierarchy.

The code compiled in the XCODE 4 for iOS6 support is working fine. (tested on the iphone 5s with iOS7)

EDIT:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath
{
static NSString *CellIdentifier = @"CellAloj";
AlojamentoTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell==nil){
    posicao=0;
}
posicao=70+(100*indexPath.row);
[bdAl.arrayFotos removeAllObjects];    NSMutableString *simbpreco=[[NSMutableString alloc]init];
NSNumber *id1=[bdAl.idAlojamento objectAtIndex:indexPath.row];
[self drawviewRank:[id1 integerValue]];
//posicao=posicao+100;

cell.backgroundView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"aloj_cell3.png"]];
//Não aparecer mais celulas depois da última com conteúdo
UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
self.tableView1.tableFooterView = footer;
///////////////
[bdAl SelectFotos:[[bdAl.idAlojamento objectAtIndex:indexPath.row]integerValue]];
cell.nomeAloj.text=[bdAl.arrayNomeAloj objectAtIndex:indexPath.row];
cell.imgAloj.image=[[UIImage alloc]init];
UIImage *imagem=[bdAl.arrayFotos objectAtIndex:0];
cell.tipo.text=[bdAl.arrayTipoAloj objectAtIndex:indexPath.row];
cell.labelLocalidade.text=[bdAl.arrayLocalidade objectAtIndex:indexPath.row];
cell.imgAloj.image=imagem;
CALayer * l = [cell.imgAloj layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];
cell.detailAloj.text=[bdAl.arrayDescAloj objectAtIndex:indexPath.row];
int i=[[bdAl.arraypreco objectAtIndex:indexPath.row]integerValue];
for (int j=0; j<i; j++){
    [simbpreco appendString:@"€"];
}
[tableView1 setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

[tableView1 setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"nav_menu.png"]]];
cell.preco.text=simbpreco;
return cell;

EDIT2:

Storyboard: 在此输入图像描述

EDIT3: This method returns 17 rows:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [bdAl.arrayNomeAloj count];
}

And the numberOfSectionsInTableView method:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

EDIT4:

#import <UIKit/UIKit.h>
#import "AlojamentoTableViewController.h"
@interface AlojamentoTableCell : UITableViewCell{

}
@property (strong, nonatomic) IBOutlet UILabel *tipo;
@property (strong, nonatomic)IBOutlet UILabel *nomeAloj;
@property (strong, nonatomic)IBOutlet UILabel *detailAloj;
@property (strong, nonatomic)IBOutlet UIImageView *imgAloj;
@property (strong, nonatomic) IBOutlet UILabel *labelLocalidade;
@property (strong, nonatomic)IBOutlet UILabel *preco;
@end

I figure it out the problem:

I had this method:

-(void)RemoveAllObjects{
    [bdAl.arrayLocalidade removeAllObjects];
    [bdAl.idAlojamento removeAllObjects];
    [bdAl.arrayDescAloj removeAllObjects];
    [bdAl.arrayFotos removeAllObjects];
    [bdAl.arrayMail removeAllObjects];
    [bdAl.arrayTipoAloj removeAllObjects];
    [bdAl.arrayMorAloj removeAllObjects];
    [bdAl.arrayNomeAloj removeAllObjects];
    [bdAl.arrayStar removeAllObjects];
    [bdAl.arrayTelf removeAllObjects];
    [bdAl.arraypreco removeAllObjects];
    NSArray *subviews = [self.tableView1 subviews];
    for (int i=0; i<[subviews count]; i++)
    {
       [[subviews objectAtIndex:i] removeFromSuperview];
    }
    //posicao=90;
}

to clear all the content when the user begins to use the Search Feature. This method was called in ViewWillAppear.

I remove it and all things are working right.

Thank you all(I have to review all my code, I know.)

EDIT: The UISerachView hiearchy changed in iOS7 that's why the subviews count failed.

My guess is that there is something wrong with your constraints. Views are getting moved/resized and that is causing some parts not to show properly. Other parts show because the views that are being resized are not clipping and so bits you draw yourself are getting placed outside of the view they should be in.

Use the following code to add a border around different views to see where they are. I suspect that you will find that many of them aren't being placed where you think they are.

Another thing to try is to turn off autolayout in your storyboard.

@interface UIView (Extension)

- (void)addBorder;
@end


@implementation UIView (Extension)

- (void)addBorder
{
    [self.layer setBorderColor: [[UIColor redColor] CGColor]];
    [self.layer setBorderWidth: 2];
}

@end
  • EDIT -

Just before this line cell.nomeAloj.text=[bdAl.arrayNomeAloj objectAtIndex:indexPath.row]; add the line assert(cell.nomeAloj); and tell me what happens when you run the code.

Since you say that cellForRowAtIndexPath gets called that means there should be cells generated. One thing I can think of is that your UITableView or UIView actually has no size.

So a normal UITableView should be able scroll. Are you able to scroll? or even interact with that table?

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM