How to assign file owner when using UITableView registerNib: load custom UITableViewCell from nib?

So, I was looking for using UITableView's registerNib: and [dequeueReusableCellWithIdentifier: forIndexPath:] to load a custom UITableCellView from the NIB . Here are the important bits of my controller:

 - (void)viewDidLoad [super viewDidLoad]; self.tableView.bounces = NO; [self.tableView registerNib:[UINib nibWithNibName:@"ProgramListViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"]; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath TVProgramListTableViewCell *cell = (TVProgramListTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; cell.frame = CGRectMake(0, 0, CELLWIDTH, OPENCELLHEIGHT); cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.clipsToBounds = YES; cell.titleLabel.text = [NSString stringWithFormat:@"herpa derp: %i", indexPath.row]; return cell; 

So, I register the NIB when loading the view, and then using it to de-synchronize the cell. Up to this point, everything works as I expect. My custom TVProgramListTableViewCell loads correctly from the NIB and it connects IBOutlet .

NIB contains a view with a button in it that I would like to have fire events for the controller. I can set the File Owner type as the Table View Controller class, but I don’t know how to actually connect the File Owner.

Now, if I used loadNibNamed: and downloaded NIB myself, connecting to the file owner would be easy. Is there a way to achieve this using registerNib ? Besides being unable to attach a File Owner, this seems like the perfect way to use custom cells in a UITableView .

+7
source share
1 answer

As far as I know, there is no way to set the file owner on your table view controller and connect the action method to the button in the xib file - I tried this and the application crashes. Usually this is done to call addTarget: action: forControlEvents: on your button in the cellForRowAtIndexPath method and pass yourself as the target.

+2
source

All Articles