I’m building an app where I use custom tableView Cells and i’m not really sure, if I do it right:
I’m not really sure about the cellOwner for example…
And the basic problem is, that all outlets that I defined and hocked up in IB, are nil at runtime.
Here is what I did:
- build a custom subclass of UITableViewCell (ProductListTableViewCell)
- made a nib, containing a UITableViewCell as root element
- set both the className and the owners Type of the cell to ProductListTableViewCell
- set the reuse identifier
- then put a couple of Labels etc onto the cell and generated the outlets via drag and drop
- double checked that all outlets are hocked up correctly.
The outlets however are all nil.
What am I doing wrong ?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"ProductListTableViewCell";
ProductListTableViewCell *cell =(ProductListTableViewCell*) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
ProductListTableViewCell *cellOwner = [[ProductListTableViewCell alloc]init];
UINib* nib = [UINib nibWithNibName:@"ProductListTableViewCell" bundle:nil];
cell =(ProductListTableViewCell*) [[nib instantiateWithOwner:cellOwner options:nil]objectAtIndex:0];
}
// all outlets are nil here
try this