Ans
Ans

Reputation: 3581

One Custom UITableViewCell in different UITableView of two UIViewControllers

My problem is like this

  1. I have one custom UITableView cell class with xib file.
  2. In Interface builder, I have set its File's Owner as VC1. (subclass of UIViewController having one UITableView)
  3. Everything is good till now. UITableView shows data in VC1.
  4. Now I want to use same customCell in a UITableView of VC2.
  5. At this stag, what should I set in File's Owner of my cell? VC1, or VC2?

Hope I clear the situation.

Upvotes: 0

Views: 95

Answers (2)

Kai Engelhardt
Kai Engelhardt

Reputation: 1300

Have you looked at - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier from the UITableView class?

This method lets you register a cell from a seperate xib. You could register the same cell in multiple tableViews.

Example:

UINib *nib = [UINib nibWithName:@"CustomCell.xib" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"CustomCell"];

Now you can use the custom cell in tableView:cellForRowAtIndexPath: with the reuse identifier specified above.

Upvotes: 1

Isaac
Isaac

Reputation: 10834

You probably should define a view controller class that inherits from your ParentVC and from which VC1 and VC2 (and any other view controllers that will use the particular custom cell XIB) inherit, so that you can define the outlets and whatnot that you want to use in this new view controller class and use this new view controller class as the File's Owner in the XIB.

Upvotes: 0

Related Questions