自定义表视图单元格中没有可见的视图 [英] No Visible View in Custom Table View Cell
问题描述
我正在做有关 tableView
和 tableViewCell
的练习.而且自定义视图单元格存在一些问题.
I am doing an exercise about tableView
and tableViewCell
. And I am having some problems with custom view cells.
我已经使用名为 newCellView.xib
的.xib文件创建了自己的自定义 tableViewCell
.我需要.h和.m文件,我选择超类作为 UITableViewCell
.
I have created my own custom tableViewCell
with .xib file called as newCellView.xib
. I have required .h and .m files and I choose super class as UITableViewCell
.
在名为 TableViewController
的视图控制器中,我正在使用这样的默认单元格创建一个表.
In my view controller called as TableViewController
I was creating a table with default cells like this.
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = [showNames objectAtIndex:[indexPath row]];
cell.imageView.image = [UIImage imageNamed:[iconArray objectAtIndex:[indexPath row]]];
return cell;
}
一旦创建了自己的自定义视图.我将 newViewCell.h
导入我的 viewController
中,并更新了这样的代码.
Once I have created my own custom view. I imported newViewCell.h
into my viewController
and I updated the code like this.
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *newCellViewString = @"newCellView";
newCellView *cell = [tableView dequeueReusableCellWithIdentifier:newCellViewString];
//newCellView *cell = [[newCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:newCellView];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"newCellView" owner:self options:nil];
cell = (newCellView *)[nib objectAtIndex:0];
}
但是,当我运行该应用程序时,我看到一个空白页面,就像我没有相关视图一样.也许我忘记了要添加的一些连接.我什至看不到要查看的空白单元格.只有白色的空白页.任何帮助将是巨大的.谢谢.
But when I run the app I see a blank page, like I have no related view. Maybe I forgot some connections to add. I can't even see empty cells to view. Only a white blank page. Any help would be great. Thanks.
编辑其他文件
这是我的.h和.m文件.
Here are my .h and .m files.
#import <UIKit/UIKit.h>
@interface newCellView : UITableViewCell <UITableViewDelegate>
@property (nonatomic, strong) IBOutlet UILabel *nameLabel;
@property (nonatomic, strong) IBOutlet UIImageView *iconImageView;
@property (retain, nonatomic) IBOutlet UIButton *extendButton;
@end
.m文件
#import "newCellView.h"
@implementation newCellView
@synthesize nameLabel;
@synthesize extendButton;
@synthesize iconImageView;
- (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
}
- (void)dealloc {
[extendButton release];
[nameLabel release];
[iconImageView release];
[super dealloc];
}
@end
推荐答案
我找到了答案.除了单元格视图的位置,所有代码在我的代码中都运行良好.
I found the answer. Everything was working good in my code except the positioning of the cell view's.
项目使用自动布局作为默认属性.因此,每当我看到白页时,单元格实际上都超出了范围.我禁用了自动版式,并通过尺寸检查器设置了项目的移动属性.
Project was using autolayout as a default property. So whenever i see the white page actually cells were out of bounds. I disabled autolayout and set movement properties of the items from size inspector.
感谢您的努力.
这篇关于自定义表视图单元格中没有可见的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!