我正在使用故事板,但我的自定义单元格位于xib中。表格在那里,但没有单元格出现。我的代码:
OurTeamCell.h
#import <UIKit/UIKit.h>
@interface OurTeamCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *LabelNome;
@property (strong, nonatomic) IBOutlet UILabel *LabelOcupacao;
@property (strong, nonatomic) IBOutlet UIImageView *ImageFoto;
@property (strong, nonatomic) IBOutlet UIImageView *fundoCellImage;
@end
OurTeamCell.m
#import "OurTeamCell.h"
#import <QuartzCore/QuartzCore.h>
@implementation OurTeamCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
self.fundoCellImage.layer.cornerRadius = 5;
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
OurTeam.h
#import <UIKit/UIKit.h>
@interface OurTeam : UIViewController
@property (strong, nonatomic) IBOutlet UITableView *tableViewTeam;
@end
OurTeam.m
#import "OurTeam.h"
#import "OurTeamCell.h"
#import <QuartzCore/QuartzCore.h>
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
@interface OurTeam ()
@end
@implementation OurTeam{
NSMutableDictionary *listaTeam;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableViewTeam.backgroundColor = [UIColor clearColor];
self.tableViewTeam.opaque = NO;
self.tableViewTeam.backgroundView = nil;
self.tableViewTeam.layer.cornerRadius = 5;
NSMutableArray *listaNomes = [NSMutableArray new];
[listaNomes addObject:@"TESTE"];
[listaTeam setObject:listaNomes forKey:@"nomes"];
if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"fundo~ipad.png"]];
} else {
if (isiPhone5)
{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"fundo4inch.png"]];
}
else
{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"fundo.png"]];
}
}
}
-(int) numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(int) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [listaTeam count];
}
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
CGImageRef imgRef = [image CGImage];
CGImageRef maskRef = [maskImage CGImage];
CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask(imgRef, actualMask);
return [UIImage imageWithCGImage:masked];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
OurTeamCell *cell = (OurTeamCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"OurTeamCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [UIView new];
cell.selectedBackgroundView = [UIView new];
cell.LabelNome.text = [[listaTeam objectForKey:@"nomes"] objectAtIndex:indexPath.row];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
编辑:
这是表格视图的显示方式:
答案 0 :(得分:2)
添加:
[self.tableViewTeam reloadData];
作为-viewDidLoad
方法中的最后一行代码。
您需要通过调用-reloadData
方法告诉表格视图您的数据已更新...
<强> [编辑] 强>
正如OP评论中所述,你还需要在[[listaTeam objectForKey:@"nomes"] count]
方法中返回nomes numberOfRowsInSection
的数量。
答案 1 :(得分:1)
也许可以尝试将其添加到-(void)viewDidLoad
OurTeam.m
[self.tableView registerClass:[OurTeamCell class] forCellReuseIdentifier:@"SimpleTableCell"];
答案 2 :(得分:1)
您从未创建过listaTeam字典。您不能使用setObject:forKey:直到您为init分配字典(或使用其他字典创建方法之一)。您还需要将您在numberOfRowsInSection中返回的内容更改为0xFADE在其评论中所说的内容。
listaTeam = [NSMutableDictionary dictionary];
[listaTeam setObject:listaNomes forKey:@"nomes"];