2

我正在练习子类 UItableView 单元格并在下面不断收到此错误,我还添加了 conditionCell 代码:

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) 

下面是我的条件单元格代码:

#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

有人能帮助我吗?

这是标题代码:

#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

这是我的表格视图代码:

#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
4

5 回答 5

1

根据我的经验:

如果将UIControl IBOutlet Interface Builder 中的任何连接到XIB's File's Owner. 并且意外地(或错误地IBOutlet被删除了,File's OwnerUIControl 可能仍然存在(availabel)的引用XIB,当时产生了以下错误

“由于未捕获的异常‘NSUnknownKeyException’而终止应用程序:原因”

您应该根据上述问题找到您的问题。

于 2013-02-26T04:03:47.107 回答
0

几天前我遇到了同样的问题。我不小心将故事板中的 UITableView 而不是 UITableViewController 子类化了。如果您通过情节提要执行此操作,请检查以确保您的子类化正确。可能就是这样

于 2013-02-26T03:21:30.563 回答
0

如果您在连接到 xib 文件时更改了“title”属性的名称,则可能会发生这种情况。断开它并重新连接它,这可能会解决您的问题。

于 2013-02-26T03:25:34.033 回答
0

如果您在 XIB 中使用 conditionCell 的出口连接,请删除它们并重新连接,尤其是标题属性(如果有)。

于 2013-02-26T04:59:37.917 回答
0

您已经创建了一个自定义单元格,并且与子视图的 IBOutlet 连接未正确建立。连接所有插座。

于 2013-02-26T09:45:06.117 回答