0

I have custom and very simple UITableViewCell. I just want to init my table view by using new technique in ios 6, i.e. registering class and after deque cell with identifier. So i have UITableViewController, inside the tableview i have one prototype cell , here is the image of it.enter image description here

at first i forgot to register the class in viewDidLoad method inside the Table View controller and it was working fine. here is the code.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"customCellIdentifier" forIndexPath:indexPath];

    return cell;
}

but in this case

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

is not called during the cell init process.

and the after i put the register class functionality inside the viewdidload. here is the code

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@"customCellIdentifier"];

}

after it the - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier starts invoking but in this case the cells are absolutely empty when i'm trying to debug , inside the initwithstyle method all the outlets are nil. whats going on? what i'm doing wrong?

1 Answer 1

0

If you have defined the cell as prototype cell for the table view in your nib/storyboard file, then you don't have to register it, that is done automatically. But in that case, initWithCoder: is called for cells instantiated from the nib/storyboard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.