自定义UITableViewCell给了我:这个类不符合键值编码 [英] Custom UITableViewCell gives me: this class is not key value coding-compliant
问题描述
首先,此讨论无法解决我的问题。
First of all, this discussion did not solve my problem.
自定义UITableViewCell子类:此类不是符合编码的键值
设置:
我在中有一个Person对象数组MainViewController
。
想要在 AllContactsViewController
中的 UITableView
中显示对象。
I have an array of Person objects in MainViewController
.
Want to show the objects in an UITableView
in AllContactsViewController
.
问题:
使用默认 UITableViewCell $ c $时,所有工作正常C>。
当我使用我的自定义 TableCell
时,我收到一个指向
的错误,该类不符合键值编码。
All works as expected when use the default UITableViewCell
.
When I use my custom TableCell
I get an error pointing to
that this class is not key value coding-compliant.
我在 IB
中连接我的三个 outlet
中的任何一个后,就会发生此错误我的 TableCell
类。
This error occurs right after I connect ANY of my three outlets
in IB
with my TableCell
Class.
注意:
TableCell
有三个属性: name
& 电子邮件
标签+ imageView
。
TableCell
has three properties: a name
& email
label + imageView
.
希望你能提供帮助。
TableCell.h
#import <UIKit/UIKit.h>
@interface TableCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
TableCell.m
#import "TableCell.h"
@implementation TableCell
@synthesize nameLabel, imageView, emailLabel;
AllContactsViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdent = @"TableCell";
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdent];
if (cell == nil) {
NSArray *array = [[NSBundle mainBundle]loadNibNamed:@"TableCell" owner:self options:nil];
cell = [array objectAtIndex:0];
}
NSString *firstAndLastnameString =
[NSString stringWithFormat:@"%@ %@",
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] firstName],
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] lastName]];
cell.nameLabel.text = firstAndLastnameString;
cell.emailLabel.text =
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] eMail];
cell.imageView.image =
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] contactPicture];
return cell;
}
更新:
也许截图将有助于IB。
Maybe a screenshot will help from IB.
已添加完整AllContactsViewController.h
Added full AllContactsViewController.h
#import <UIKit/UIKit.h>
#import "VCDelegate.h"
#import "TableCell.h"
@interface AllContactsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) id <VCDelegate>delegate;
@property (weak, nonatomic) IBOutlet UITableView *allContactsTableView;
@property (strong, nonatomic) NSMutableArray *allContactsArray;
@property (assign) int currentArrayIndexNumber;
- (IBAction)closeBtnTapped:(id)sender;
@end
推荐答案
如果你要连接文件所有者的出口,你应该做的不同:
If you are connecting the outlets from the file's owner, you should do different:
1 - 定义你的TableCell类的UITableViewCell的类:
1 - Define the class of the UITableViewCell to your TableCell class:
2 - 连接出口不是来自文件所有者,而是来自对象列表中的TableCell:
2 - Connect the outlets not from File's Owner, but from TableCell in the objects list:
这篇关于自定义UITableViewCell给了我:这个类不符合键值编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!