0

Given that we have an UITableView with only unique cells - for example we display data from a single model that has title and description. Cell for title is different than one for description. So there will be only one cell of type TitleCell and one of type DescriptionCell in the table view. Two cells in total in that table view.

Are there any drawbacks of creating UITableViewCells in ViewDidLoad and storing them in ivars? Then here's how the cell is passed to the table view.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return myCellReference;
    }...

This way don't even call dequeueReusableCellWithIdentifier. Is this approach ok?

1
  • 1
    For the sake of making the code readable, I'd keep it in cellForRowAtIndexPath. No point in doing it in viewDidLoad, when cellForRowAtIndexPath does the job fine and is more intuitive. If you don't want to call dequeueReusableCellWithIdentifier, then don't, but you should probably stick with cellForRowAtIndexPath.
    – Rob
    Oct 25, 2013 at 15:21

2 Answers 2

0

No it's not. Why are you doing something that the framework already provides for free? I would recommend that if, for some reason, the dequeueReusableCellWithIdentifier performance/behaviour, wouldn't suit your specific case. Which I doubt.

2
  • This way is easier to calculate height of the cell if it's variable, isn't it? I can directly access cell's subviews.
    – Lubiluk
    Oct 25, 2013 at 15:16
  • Not necessarily. What if you tomorrow decide to have 3 or 4 rows? Will you keep doing if/elses to select the right cell and height?
    – Rui Peres
    Oct 25, 2013 at 15:22
0

If I understand correctly, your table will only have a total of 2 cells displayed?

In that case what you're proposing will work just fine.

1
  • Yes, just two cells. Thanks
    – Lubiluk
    Oct 25, 2013 at 15:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.