的iOS UITableView的错误

问题描述:

我练子类的UITableView细胞,并保持低于收到此错误,我还添加了conditionCell代码:的iOS UITableView的错误

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 
+1

请发布一些与你的'conditionCell'有关的代码。 – MishieMoo 2013-02-26 03:13:16

+0

@MishieMoo发布 – 2013-02-26 03:15:01

+0

那么这里没有'setValue:forKey'的用法。也许还发布你的'tableView:cellForRowAtIndexPath:'方法?或者使用这个类的任何其他代码。 – MishieMoo 2013-02-26 03:17:04

从我的经验:

如果您在Interface Builder连接任何UIControl IBOutletXIB's File's Owner。并意外地(或通过错误IBOutletFile's Owner未删除的UIControl参考可以保持(availabel)在XIB,当时以下错误产生

“终止应用程序由于未捕获的异常' NSUnknownKeyException':Reason“

您应该在上述问题中找到您的问题依据。

+1

+1绝对同意 – Yogi 2013-02-26 06:00:33

我遇到了同样的问题,前几天。我意外地在故事板中分类了UITableView而不是UITableViewController。如果您是通过Storyboard进行检查以确保您的子类正确。那可能是

+0

好吧我正在检查 – 2013-02-26 03:24:01

+0

我说得对。我是UITableViewController的子类,但它不工作。 – 2013-02-26 03:27:35

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

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

您已经创建了自定义单元格,并且子视图的IBOutlet连接没有正确设置。连接所有的网点。