0

I Know this question is asked again and again here, but did not find any solutions for my problem.I'm creating a Custom UITableViewCell through xib and trying to load it.in my VC called ACSummaryVC

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"SimpleTableCell";

    AcSummaryCell *cell = (AcSummaryCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AcSummaryCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
}

AcSummaryCell is a subclass of UITableViewCelland it has an UILabel IBOutlate called acLabel.when i compile the project i get following error-

`Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ACSummaryVC 0x71465c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key acLabel.'`

i have created connection of acLabel in AcSummayCell class, but i'm getting error from ACSummaryVC? What i'm doing wrong?

Edit:- according to Mani's answer bellow i'm connecting outlate to file owner and it is wrong instead i've to connect outlate to custom cell.but when i try this i did not get my outlate to connect with instead i'm getting like this image - enter image description here

Now question is How to connect my outlate with custom cell? here is my AcSummayCell.h

@interface AcSummayCell : UITableViewCell
@property(nonatomic, retain)IBOutlet UILabel* acLabel;
@property(nonatomic, retain)IBOutlet UILabel* namelbl;
@property(nonatomic, retain)IBOutlet UILabel* cBalancelbl;
@property(nonatomic, retain)IBOutlet UILabel* avBalancelbl;

and AcSummayCell.m

#import "AcSummayCell.h"

@implementation AcSummayCell
@synthesize acLabel = _acLabel;
@synthesize namelbl = _namelbl;
@synthesize cBalancelbl = _cBalancelbl;
@synthesize avBalancelbl = _avBalancelbl;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
Bharat
  • 2,987
  • 2
  • 32
  • 48

4 Answers4

5

You have setup a wrong outlet connection. Its because you have connected your label's outlet to your file's owner. Remove that label outlet connection out of file's owner and connect the outlet pointing to your custom cell. It should work.

Mani Kandan
  • 629
  • 4
  • 12
  • Can you please explain it because when i'm trying to connect to custom cell it did not show my outlate to connect instead it shows accessoryView, backgroundView etc. – Bharat Aug 27 '13 at 06:03
  • 2
    Check whats the class you have selected in your Identity Inspector of XIB. It should be your custom tableviewcell's class name (in your case, AcSummayCell). Click on the File's Owner in your XIB and open up the identity inspector and change the class name to AcSummayCell. – Mani Kandan Aug 27 '13 at 06:45
  • Thanks Mani you have saved me.. i was doing that for file owner.Now it works. – Bharat Aug 27 '13 at 06:51
1

follow this... for custom tableview cell UITableViewCell Space between Title and Subtitle -iOS

or this awesome tutorial

http://www.appcoda.com/customize-table-view-cells-for-uitableview/

Community
  • 1
  • 1
Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
  • Thanks mayank i'm already following that tutorial, but did not get the thing "connect the outlet pointing to your custom cell"..when i right click on my custom cell in nib to connect with outlate it does not show my outlates to connect with? – Bharat Aug 27 '13 at 06:10
1

follow this code properly....

AudioCell.h

#import<UIKit/UIKit.h>

@interface AudioCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *artistLabel;
...


@end

AudioCell.m

#import "AudioCell.h"

@implementation AudioCell

@synthesize titleLabel = _titleLabel, artistLabel = _artistLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
    // Initialization code
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

Now implement this code in your class at the TableView Data Source....

#import "AudioCell.h"
.....
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"AudioCell";

AudioCell *cell = (AudioCell *)[self.audioFeedTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
    cell = (AudioCell *)[nibArray objectAtIndex:0];
    [cell configurePlayerButton];
}

// Configure the cell..


cell.titleLabel.text = [nameArray objectAtIndex:indexPath.row];
cell.artistLabel.text = [commentsArray objectAtIndex:indexPath.row];
....

return cell;
}

Link your custom TableViewCell with the subClass by the same way.... enter image description here

Lutful Kabir
  • 119
  • 6
0

I see your mistakes:

You don't specify Cell class and reuse identifier in your customCell Create custom cell AcSummaryCell:UITableViewCell first then choose class for tableCell in the nib Cell. Also assign cell identifier in NIB. If correct , your cell must display AcSummaryCell-SimpleTableCell in Object field.

For hookup to IBOutlet, just choose editor(show assistant editor) -> then choose Automatic-AcSummaryCell.h -> then drag and hookup IBOutlet you want.

Kundan
  • 3,084
  • 2
  • 28
  • 65
LE SANG
  • 10,955
  • 7
  • 59
  • 78