Why customizing cell in UITableView is receiving error: hasn't received initWithFrame: or initWithCoder?

I followed a tutorial on youtube and I followed all the steps very carefully three times. but I received this error:

2014-09-27 04:02:42.248 JourneyTracker[6667:306214] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Requesting the window of a view 
(<CustomeCellTableViewCell: 0x8362f6f0; baseClass = UITableViewCell; frame = (0 0; 0 0); 
transform = [0, 0, 0, 0, 0, 0]; alpha = 0; opaque = NO; autoresize = W; layer = (null)>) with a nil layer. This view probably hasn't received initWithFrame: or initWithCoder:.'
            *** First throw call stack:
                0   CoreFoundation                      0x00e0edf6 __exceptionPreprocess + 182

I have searched many related questions and most of them, they forgot to init a button etc. But as you can see in following I have two label and init them:

@implementation CustomeCellTableViewCell{

    UILabel *_nameValue;
    UILabel *_weightValue;


- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
        CGRect nameLableRect = CGRectMake(0, 5, 70, 15);
        UILabel *nameLable = [[UILabel alloc] initWithFrame:nameLableRect];
        nameLable.textAlignment = NSTextAlignmentRight;
        nameLable.text = @"name";
        nameLable.font = [UIFont boldSystemFontOfSize:12];
        [self.contentView addSubview:nameLable];

        CGRect weightLableRect = CGRectMake(0, 26, 70, 15);
        UILabel *weightLable = [[UILabel alloc] initWithFrame:weightLableRect];
        weightLable.textAlignment = NSTextAlignmentRight;
        weightLable.text = @"weight";
        weightLable.font = [UIFont boldSystemFontOfSize:12];
        [self.contentView addSubview:weightLable];

        //Add content
        CGRect nameValueRectangle = CGRectMake(80, 5, 200, 15);
        _nameValue = [[UILabel alloc] initWithFrame:nameValueRectangle];
        [self.contentView addSubview:_nameValue];

        CGRect weightValueRectangle = CGRectMake(80, 5, 200, 15);
        _weightValue = [[UILabel alloc] initWithFrame:weightValueRectangle];
        [self.contentView addSubview:_weightValue];

    return self;

- (void)awakeFromNib {
    // Initialization code

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

- (void) setName:(NSString *)n
    if (![n isEqualToString:_name])
        _name = [n copy];
        _nameValue.text = _name;

- (void) setWeight:(NSString *)w
    if (![w isEqualToString:_weight])
        _weight = [w copy];
        _weightValue.text = _weight;



The strange thing is that when I was debugging above awakeFromNib never called and in tutorial I was following on youtube there was no "awakeFromNib" in his code!!

I have debugged this code line by line. First it goes into UITableViewController and the it goes to customize class (above) and when it comes back to UITableViewController it crashes. I have commented with <<<>>>> in my code where it crashes.

And here is my UITableViewController:

@implementation ListJourneyController

static NSString *cellIdentifier = @"CellTableIdentifier";

- (void)viewDidLoad {
    [super viewDidLoad];

 //Some implementation to modify array        

    UITableView *tableView = (id)[self.view viewWithTag:1];
    [tableView registerClass:[CustomeCellTableViewCell class] forCellReuseIdentifier:cellIdentifier];


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    // Return the number of sections.
    return 1;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    // Return the number of rows in the section.
    return numberOfRow;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//<<<<<This point it goes to customize class and when it comes back it crashes>>>>>>
    CustomeCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    Journey *rowData = items[indexPath.row];
    cell.name = @"afshar";
    cell.weight = @"Hila";
    return cell;


Update After solving this problem now both items appear in same field!


You never call the super implementation inside your CustomeCellTableViewCell class. That's why you're getting the error. Add the call to super initWithStyle:reuseIdentifier and you'll be good to go.

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Now do your setup code
    return self;

Need Your Help

How to parse command line arguments

c# command-line

I want to parse a set of command line arguments that look like:

WPF: Detect when selected item changes

wpf data-binding binding listbox selecteditem

I have a control that is data-bound to a ListBox. All of the bound properties are being updated correctly. However, the control needs to know when the selected item changes so that it can do some o...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.