So i've been looking at using UITableView's
registerNib:
and [dequeueReusableCellWithIdentifier: forIndexPath:]
for loading up a custom UITableCellView
from a NIB
. Here are the important bits from 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'm registering the NIB
when the view loads and then utilizing it for cell dequeuing. Up to this point everything is working like i expect it to. My custom TVProgramListTableViewCell
is being properly loaded from the NIB
and it's IBOutlet
is being wired up.
The NIB
contains a view with a button in it that i would like to have fire events to the controller. I can set the File's Owner type as my Table View Controller class but i do not know how to actually wire up the File's Owner.
Now if i was using loadNibNamed:
, and loading the NIB
myself, wiring up the File's Owner would be easy. Is there any way to achieve this while utilizing registerNib
? Other than not being able to wire up the File's Owner this seems like the perfect way of using custom cells in a UITableView
.
As far as I know, there's no way to set the file's owner to your table view controller and connect up an action method to a button in a xib file -- I've tried that, and it crashes the app. The way this is normally done is to call addTarget:action:forControlEvents: on your button in the cellForRowAtIndexPath method, and pass self as the target.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With