自定义单元格未出现在表格视图
问题说明
我使用故事板.我为我的 Cell 创建了新类,在故事板中我用重用标识符userFullCell"编写.我的 Cell 类 .h
I use storyboards. I create new class for my Cell, in storyboard I write in Reuse Identifier "userFullCell". My Cell class .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
}
property image 和 shortTitle 在情节提要中与 UILabel 和 UIImageView 连接在 Cell 中
property image and shortTitle connected in storyboard with UILabel and UIImageView in Cell
然后在我的 UITableView 类中我导入UseFullLinksCell.h"并在 viewDidLoad 中写道:
Then in my class with UITableView I import "UseFullLinksCell.h" and in viewDidLoad wrote:
[self.tableView registerClass:[UsefullLinksCell class] forCellReuseIdentifier:@"userFullCell"];
tableView 是我的出口:
tableView is my outlet:
@property (weak, nonatomic) IBOutlet UITableView *tableView;
然后我尝试创建单元格:
and then I try to create cells:
- (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 抱歉我不能提供故事板的截图,因为我不是用我的电脑写的,如果你想要,我稍后提供图片
So, cell initialize, but image and text not assigned, and after going end of method return 0x0000000 for cell. If I create for standart cell code in this method, I mean UITableViewCell *cell, there is all good. Where I could make mistake? PS Sorry I can not give screenshots from storyboard, because I write from not my computer, if you want, I provide images later
正确答案
您应该注册您制作自定义单元格的 xib 文件(使用 registerNib:forCellReuseIdentifier:),而不是类.另外,我不知道这是否会有所作为,但请替换:
You should register the xib file (with registerNib:forCellReuseIdentifier:) where you made your custom cell, not the class. Also, I don't know if this will make a difference or not, but replace this:
UsefullLinksCell *cell = (UsefullLinksCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
有了这个(注意方法末尾的 forIndexPath:):
With this (notice the forIndexPath: at the end of the method):
UsefullLinksCell *cell = (UsefullLinksCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
编辑后:
如果在情节提要中的表格视图中添加了一个自定义单元格,并为其指定了标识符userFullCell",那么您不需要注册任何东西——事实上,注册您的类使其不起作用.所以,只需注释掉那个 register 语句,看看它是否有效.
If added a custom cell to your table view in the storyboard, and gave it the identifier "userFullCell", then you don't need to register anything -- in fact, registering your class makes it not work. So, just comment out that register statement, and see if that works.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgjhhb
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20