mercredi 24 juin 2015

UITableViewCell Subclass with custom init method

I'm creating a custom UITableViewCell and I would like to create a custom init method so that I can inject some data (an array) to it. Every time I do this however I get a crash on the init method itself. What is the best way to accomplish this? Any help would be greatly appreciated.

Here is my code for cellForRowAtIndex:

 // Setup Jam Object
    PFObject* jamObject = [postsArray objectAtIndex:indexPath.section];
    Jam *jam = [[Jam alloc] initWithJamObject:jamObject];

    cellIdentifier = @"MainCell";

    Post_MainCell *cell = (Post_MainCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    cell.contentView.backgroundColor = UIColorFromRGB(0xDBDBDB);
    cell.parentTableViewController = self;
    cell.jam = jam;
    [cell initialize];

    return cell;

What I would like to do is create an init method so I can pass in the Jam object on initialization. Something like this:

-(id)initWithFrame:(CGRect)frame andJam:(Jam *)jam {
self = [super initWithFrame:frame];
if (self)
    self.jam = jam;

return self;

See more ..

Aucun commentaire:

Enregistrer un commentaire