【发布时间】:2013-02-14 07:22:39
【问题描述】:
我使用故事板。我在情节提要中为我的 Cell 创建了新类,我用 Reuse Identifier “userFullCell” 编写。我的 Cell 类.h
#import <UIKit/UIKit.h>
@interface UsefullLinksCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *shortTitle;
@end
.m 默认
#import "UsefullLinksCell.h"
@implementation UsefullLinksCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
属性 image 和 shortTitle 在情节提要中与单元格中的 UILabel 和 UIImageView 连接
然后在我的 UITableView 类中,我导入“UseFullLinksCell.h”并在 viewDidLoad 中写道:
[self.tableView registerClass:[UsefullLinksCell class] forCellReuseIdentifier:@"userFullCell"];
tableView 是我的出路:
@property (weak, nonatomic) IBOutlet UITableView *tableView;
然后我尝试创建单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"userFullCell";
UsefullLinksCell *cell = (UsefullLinksCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *info = resourceArray[indexPath.row];
if(info){
cell.image.image = info[@"logo"];
cell.shortTitle.text = info[@"title"];
}
return cell;
}
因此,单元格初始化,但未分配图像和文本,并且在方法结束后为单元格返回 0x0000000。如果我用这种方法为标准单元格代码创建,我的意思是 UITableViewCell *cell,一切都很好。我在哪里会犯错? PS对不起,我不能提供故事板的截图,因为我不是用我的电脑写的,如果你愿意,我稍后会提供图片
【问题讨论】:
-
什么是resourceArray,你在哪里初始化单元格?
-
resourceArray - 带有字典的数组,包含我的信息。它适用于标准电池。我需要像写的 V-Xtreme 一样初始化吗?我需要创建 xib 吗?我使用故事板,所以我需要用 xib 文件重新创建?
标签: ios objective-c xcode uitableview