2

I'm practicing subclass UItableView cell and keep receiving this error below, I also added the conditionCell code:

013-02-25 22:07:24.757 tableForms[52558:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<conditionCell 0x715d930> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key title.'
*** First throw call stack:
(0x1c94012 0x10d1e7e 0x1d1cfb1 0xb7de41 0xaff5f8 0xaff0e7 0x65f23 0xb29b58 0x233019 0x10e5663 0x1c8f45a 0x231b1c 0xc733f 0xc7615 0xc7645 0x2d7e 0xd08fb 0xd09cf 0xb91bb 0xc9b4b 0x662dd 0x10e56b0 0x2290fc0 0x228533c 0x2290eaf 0x1052bd 0x4db56 0x4c66f 0x4c589 0x4b7e4 0x4b61e 0x4c3d9 0x4f2d2 0xf999c 0x46574 0x4676f 0x46905 0x4f917 0x1396c 0x1494b 0x25cb5 0x26beb 0x18698 0x1befdf9 0x1befad0 0x1c09bf5 0x1c09962 0x1c3abb6 0x1c39f44 0x1c39e1b 0x1417a 0x15ffc 0x238d 0x22b5)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

Here is my condition cell code below:

#import <UIKit/UIKit.h>

@interface conditionCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UITextField *conditionCell;
@property (weak, nonatomic) IBOutlet UITextField *amountCell;
@property (weak, nonatomic) IBOutlet UILabel *dollarLabel;

@end


#import "conditionCell.h"

@implementation conditionCell

- (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

Can someone help me please?

Here is the title code:

#import <UIKit/UIKit.h>

@interface titleFieldCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UITextField *title;

@end


#import "titleFieldCell.h"

@implementation titleFieldCell

- (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

Here is my table view code:

#import <UIKit/UIKit.h>

@interface TableView : UITableViewController

@end


#import "TableView.h"
#import "imageCell.h"
#import "titleFieldCell.h"
#import "descriptionCell.h"
#import "conditionCell.h"

@interface TableView ()

@end

@implementation TableView

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    //for height
    if (indexPath.row == 0 ) {
        return 130;
    }

    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //static NSString *CellIdentifier = @"Cell";
    //UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];*/
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];



    if(indexPath.row == 0){
        imageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"imageCell" forIndexPath:indexPath];
        if(!cell){

            cell = [[imageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"imageCell"];
        }
        return cell;
    }
    else if (indexPath.row == 1) {
        descriptionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"descriptionCell" forIndexPath:indexPath];
        if(!cell){

            cell = [[descriptionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"descriptionCell"];
        }
        return cell;

    }
    else if(indexPath.row == 2)
    {
        titleFieldCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"titleCell" forIndexPath:indexPath];
        if(!cell){

            cell = [[titleFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"titleCell"];
        }
        return cell;
    }
    else if(indexPath.row == 3)
    {
        conditionCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"conditionCell" forIndexPath:indexPath];
        if(!cell){

            cell = [[conditionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"conditionCell"];
        }
        return cell;
    }

    return cell;

}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

@end
GOAT
  • 601
  • 2
  • 13
  • 25
  • 1
    Please post some code pertaining to your `conditionCell`. – MishieMoo Feb 26 '13 at 03:13
  • Well there's no `setValue:forKey` usage there. Perhaps also post your `tableView:cellForRowAtIndexPath:` method? Or any other code that uses this class. – MishieMoo Feb 26 '13 at 03:17
  • The posted code is fine as-is. Which line does it actually crash? You are leaving some code out having to do with **title**? Where is that code? – Jeremy Feb 26 '13 at 03:17
  • Thanks. Responded with a possible solution below. – Jeremy Feb 26 '13 at 03:27
  • 1
    Unrelated to your question, but you really should read about [Objective-C Naming Conventions](http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/Conventions/Conventions.html). – sosborn Feb 26 '13 at 03:29

5 Answers5

1

From My Experience :

If you connect any UIControl IBOutlet in Interface Builder to XIB's File's Owner. and accidentally(or By mistake) IBOutlet was deleted from the File's Owner but reference of UIControl may be remain ( availabel ) in XIB, at that time following error generated

"Terminating app due to uncaught exception 'NSUnknownKeyException':Reason"

You should find your problem base on above issue.

iPatel
  • 46,010
  • 16
  • 115
  • 137
0

I ran into the same issue a few days ago. I accidentally subclassed the UITableView rather than the UITableViewController in the storyboard. Check to ensure your subclassing correctly if you are doing it through the Storyboard. That could be it

7usam
  • 999
  • 1
  • 8
  • 23
0

This could happen if you've changed the name of your "title" property while it was connected to a xib file. Disconnect it and reconnect it and this may solve your issue.

Jeremy
  • 8,902
  • 2
  • 36
  • 44
0

If you are using the outlet connections for conditionCell in XIB, please remove them and reconnect again especially the title attribute(If any).

nkongara
  • 1,233
  • 8
  • 14
0

You have created a custom cell and the IBOutlet connection to the subviews was not made properly. Connect all the outlets.

Meera
  • 1,031
  • 6
  • 25