【发布时间】:2023-04-11 10:49:01
【问题描述】:
当我尝试将我的应用从 iOS6 转换为 iOS7/iOS8 时遇到了这个问题。
UITableView 不显示单元格(在 iOS6 中工作)。
我有一个在 iOS7 中运行良好的类似视图(它没有 UISearchView)
我尝试了几种解决方法,例如清除背景、删除 UISearchBar 等...
两个示例中的代码相似(单元格由- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathmethod 生成)
我使用 Reveal 软件来分析这个层次结构。
在 XCODE 4 中为 iOS6 支持编译的代码运行良好。 (在 iphone 5s 和 iOS7 上测试)
编辑:
- (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:
故事板:
EDIT3:此方法返回 17 行:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [bdAl.arrayNomeAloj count];
}
还有numberOfSectionsInTableView 方法:
- (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
【问题讨论】:
-
你试过关闭自动布局吗?
-
@RezaShirazian 是的,同样的问题。
-
你能粘贴你的 tableView:cellForRowAtIndexPath: 代码吗?
-
@JustinMoser 代码已添加。可能有点混乱。
-
“代码有效”这一事实并不能使它正确。你必须停止这样做。
标签: ios objective-c iphone uitableview hierarchy