jjzjj

iphone - 自定义 UITableViewCell 给我 : this class is not key value coding-compliant

coder 2023-07-25 原文

首先,这个讨论并没有解决我的问题。

Custom UITableViewCell subclass: This class is not a key value coding-compliant

设置:

我在 MainViewController 中有一组 Person 对象。 想要在 AllContactsViewController 中的 UITableView 中显示对象。

问题:

当使用默认的 UITableViewCell 时,一切都按预期工作。 当我使用我的自定义 TableCell 我得到一个错误指向 该类不符合键值编码。

在我将 IB 中的三个 outlet 中的任何一个连接到我的 TableCell 类后,立即发生此错误。

注意:

TableCell 具有三个属性:name & email 标签 + 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 有所帮助。

添加了完整的 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

最佳答案

如果您连接文件所有者的导出,您应该做不同的事情:

1 - 将 UITableViewCell 的类定义为您的 TableCell 类:

2 - 连接 socket 不是来自文件的所有者,而是来自对象列表中的 TableCell:

关于iphone - 自定义 UITableViewCell 给我 : this class is not key value coding-compliant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11985487/

有关iphone - 自定义 UITableViewCell 给我 : this class is not key value coding-compliant的更多相关文章

随机推荐