Ios CustomCell:无法在主视图上显示数据

Ios CustomCell:无法在主视图上显示数据,ios,uitableview,ios6,custom-cell,Ios,Uitableview,Ios6,Custom Cell,我制作了一个带有标签和imageView的自定义单元格,自定义单元格有一个带有标识符CustomTableCell的类customCellClass。 这是结果屏幕截图,未传递任何数据,但自定义表如您所见 这是一个.m文件,我在其中从数组*名称获取数据。请看看我错过了什么。顺便说一句,我正在尝试[self.tableView重新加载数据];在视图中,我加载了,但我不知道y,但我不可能启动它 @synthesize name = _name; - (void)viewDidLoad {

我制作了一个带有标签和imageView的自定义单元格,自定义单元格有一个带有标识符CustomTableCell的类customCellClass。 这是结果屏幕截图,未传递任何数据,但自定义表如您所见

这是一个.m文件,我在其中从数组*名称获取数据。请看看我错过了什么。顺便说一句,我正在尝试[self.tableView重新加载数据];在视图中,我加载了,但我不知道y,但我不可能启动它

@synthesize name = _name;
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.name = [NSArray arrayWithObjects:@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third", nil];
//    self.name = [[NSArray alloc]initWithObjects:@"First", @"Second", @"Third", nil];


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.name count];

}

-(void) viewDidAppear:(BOOL)animated{

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"CustomTableCell";


    customCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.nameLabel.text = [self.name objectAtIndex:indexPath.row];
    cell.imageThumb.image = [UIImage imageNamed:@"images.jpeg"];
    return  cell;


}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 78;
}


@end
顺便说一句,这是im使用的自定义表格单元格

您也可以尝试以下方法:

按如下方式创建类文件:

static NSString *CellIdentifier = @"RankingCell";

RankingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
    cell = (RankingCell *)[RankingCell cellFromNibNamed:@"RankingCell"];
}
CustomRankingCell.h

#import <UIKit/UIKit.h>

@interface CustomRankingCell : UITableViewCell

+(UITableViewCell *) cellFromNibNamed:(NSString *)nibName;

@end
并通过CustomRankingCell而不是像这样的UITableViewCell扩展自定义单元格

#import "CustomRankingCell.h"

@interface RankingCell : CustomRankingCell
{

}
然后使用如下自定义单元格:

static NSString *CellIdentifier = @"RankingCell";

RankingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
    cell = (RankingCell *)[RankingCell cellFromNibNamed:@"RankingCell"];
}
希望能有帮助

您也可以尝试以下方法:

按如下方式创建类文件:

static NSString *CellIdentifier = @"RankingCell";

RankingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
    cell = (RankingCell *)[RankingCell cellFromNibNamed:@"RankingCell"];
}
CustomRankingCell.h

#import <UIKit/UIKit.h>

@interface CustomRankingCell : UITableViewCell

+(UITableViewCell *) cellFromNibNamed:(NSString *)nibName;

@end
并通过CustomRankingCell而不是像这样的UITableViewCell扩展自定义单元格

#import "CustomRankingCell.h"

@interface RankingCell : CustomRankingCell
{

}
然后使用如下自定义单元格:

static NSString *CellIdentifier = @"RankingCell";

RankingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
    cell = (RankingCell *)[RankingCell cellFromNibNamed:@"RankingCell"];
}

希望能有帮助

这是我在表格中用于自定义单元格的内容,它可以完美地工作

static NSString *CellIdentifier = @"CustomTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

这是我在表格中用于自定义单元格的内容,它可以完美地工作

static NSString *CellIdentifier = @"CustomTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

您正在执行
alloc init
,然后将其选中为零。。。在您的情况下,如果

 cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
就这么做吧:

customCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }

您正在执行
alloc init
,然后将其选中为零。。。在您的情况下,如果

 cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
就这么做吧:

customCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }
试试这个希望对你有帮助



尝试此希望对您有所帮助。

您是否已将代理和数据源分配到表??datacource和delegate…?您确定,您的插座连接正确吗?是的,插座、代理和源中的所有内容都已清除。我以前试过在没有customcell的情况下运行它,它运行得非常好。但是在添加customcell后,它只是像图中一样显示。为什么viewDidLoad中的“super”调用丢失了?您是否已经在cellForRow中设置了断点?您是否已将代理和数据源分配给表??datacource和delegate…?您确定,您的插座连接正确吗?是的,插座、代理和源中的所有内容都已清除。我以前试过在没有customcell的情况下运行它,它运行得非常好。但是在添加customcell后,它只是像图中一样显示。为什么viewDidLoad中的“super”调用丢失了?您是否已经在cellForRow中设置了断点?同样的结果。谢谢你的回复,结果也是一样的。这里mucustomecell是customecell实现,您可以在标签“name”而不是文本字段“txtData”中获取数据。这是我刚刚实现的代码。仅[单元格设置选择样式:UITableViewCellSelectionStyleNone];缺少一个,但将尝试此选项,因此请检查customecell.xib连接。这里mucustomecell是customecell实现,您可以在标签“name”而不是文本字段“txtData”中获取数据。这是我刚刚实现的代码。仅[单元格设置选择样式:UITableViewCellSelectionStyleNone];缺少一个,但将尝试此工具。因此,请检查您的customecell.xib连接。由于未捕获的异常“NSInternalInconsistencException”,我在终止应用程序时遇到此异常,原因是:“无法在捆绑包中加载NIB:“NSBundle(loaded)”,名称为“CustomTableCell”,所以在您甚至从未尝试加载YOUR单元之前!检查自定义cellcustomCellClass*单元格的名称=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];看起来像是用小写字母“c”完成的customCellClass!!谢谢你的回复。我装错了笔尖的名字。仅此而已。由于未捕获异常“NSInternalInconsistencyException”,我有此异常终止应用程序,原因是:“无法在捆绑包中加载NIB:“NSBundle(loaded)”,名称为“CustomTableCell”,所以在您尝试加载YOUR单元之前!检查自定义cellcustomCellClass*单元格的名称=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];看起来像是用小写字母“c”完成的customCellClass!!谢谢你的回复。我装错了笔尖的名字。就这些。