Take the 2-minute tour ×

I am wanting to create a custom UITableView cell. I would like to know how to do this. I understand how to actually create it and write code for it, but how can i create 1 style and then when i have more cells added, i want the same style. How can i do this? Is there a way to create 1 custom cell and have all the other cells that i want to add later follow this cells style?Thanks for the help!

share|improve this question
add comment

3 Answers

In my projects I'm implementing method that creates custom style programmatically. Also it is possible to make custom cell via IB and when you need just take custom cell from it.

Don't forget that if you will write your code correctly then your cells will be reused and that method will be called only for number of cells that are visible in your table view.

share|improve this answer
ok how exactly are you doing this? Like could you give me some sample code just so i can see how you are adding the new cells with that format? THanks a lot! –  jessica simpson Sep 19 '11 at 1:59
add comment

may be this can help you http://iphone-bitcode.blogspot.com/2011/06/custom-tableview-cell.html

share|improve this answer
ok this is kinda what i want, i just want the cells to look like this, but i want to be able to add cells to the table with the same format. How could i do that? Thanks –  jessica simpson Sep 19 '11 at 1:58
add comment

Write a separate .h/.m/.xib for the cell, and in the .xib set File's Owner to the class you want multiple copies of it in (your table view controller class, most likely). Attach it to an IBOutlet you created in the table view controller for new cells.

Then, each time you want a cell, try and dequeueReusableCellWithIdentifier: on your tableView, and if that doesn't work (you have no reusable ones), make a new cell using your custom class by simply loading the nib file. It will automatically create an instance of the cell and attach it to your IBOutlet, and then just retain the cell and set the outlet back to nil for the next time you need to create a cell. Essentially, I mean this (I have an IBOutlet UITableViewCell *cellOutlet):

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
    static NSString *reuseIdentifier = @"CustomCell";
    UITableView *cell = [self.tableView
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"MyCustomTableViewCell"
                                      owner:self options:nil];
        cell = cellOutlet;
        self.cellOutlet = nil; // autoreleases
        cell.reuseIdentifier = reuseIdentifier;

    // configure the cell here
    return cell;
share|improve this answer
add comment

Your Answer


