Objective c UITableViewCell-RegisterInB子类未将nib作为子视图找到

Objective c UITableViewCell-RegisterInB子类未将nib作为子视图找到,objective-c,xcode,uitableview,Objective C,Xcode,Uitableview,在我的UITableView中的viewDidLoad中,我正在调用: [self registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellReuseIdentifier:@"MyCellRI"]; 然后在cellForRowAtIndexPath中,我有以下内容: MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCellRI"]; [cell

在我的UITableView中的viewDidLoad中,我正在调用:

[self registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellReuseIdentifier:@"MyCellRI"];
然后在cellForRowAtIndexPath中,我有以下内容:

MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCellRI"];

[cell setup:[items objectAtIndex:indexPath.row]];
在setup方法中,我查看了[self subview],查看子视图并根据键/值分配内容,但在这个循环中,我找到了UITableViewCellContentView,但我没有看到NIB中定义的自定义视图

在NIB中,我指定了文件所有者&我的单元格的自定义类。单元格显示我在子视图中找不到NIB视图

请告知


James

迭代子视图是一项艰巨的工作)尽量避免它。这不是很好的做法,因为它不可靠。例如,如果您决定更改自定义单元格UI,则必须更改在子视图中迭代的方法

尝试执行以下操作:

MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCellRI"];

[cell setup:[items objectAtIndex:indexPath.row]];
假设有一个带有UIImage和3个字符串(例如姓名、年龄和手机号码)的自定义手机

在自定义单元格中实现3个函数,以按如下方式设置此值:

MyCustomCell.h ... .h文件标准代码,然后在结尾

@propert(nonatomic, strong) IBOutlet UIImageView *myImage;
@propert(nonatomic, strong) IBOutlet UILabel *myFirstLabel;
@propert(nonatomic, strong) IBOutlet UILabel *mySecondLabel;
@propert(nonatomic, strong) IBOutlet UILabel *myThirdLabel;
- (void)setUIimage:(UIImage *)_image;
- (void)setFirstString:(NSString *)_string;
- (void)setSecondString:(NSString *)_string;
- (void)setThirdString:(NSString *)_string;
MyCustomCell.m:

@synthesize myImageView, myFirstLabel, mySecondLabel, myThirdLabel;

- (void)setUIimage:(UIImage *)_image {
    self.myImageView.image = _image;
}

- (void)setFirstString:(NSString *)_string {
    self.myFirstLabel.text = _string;
}

 - (void)setSecondString:(NSString *)_string {
    self.mySecondLabel.text = _string;
}

 - (void)setThirdString:(NSString *)_string {
    self.myThirdLabel.text = _string;
}
最后在tableView控制器CellForRowatineXpath中

[myCustomCell setUiImage:someImage];
[myCustomCell setFirstString:oneString];
[myCustomCell setSecondString:twoString];
[myCustomCell setThirdString:threeString];

希望这种方法能对你有所帮助。如果您有一些问题,请随时询问

您确定nib中指定的重用标识符与代码中的重用标识符相同吗?是的,我在nib中设置了重用标识符。在我的子视图循环中,当我执行[subview class]时,我得到大约15个UITableViewCellContentView类;可能您的xib文件没有UITableViewCell作为顶级对象。xib中只有一个对象,即UITableViewCell,该对象上有子类。此外,我可以看到NIB的内容,因此我知道它正在工作。只需检查我调用[cell setup:]并循环浏览屏幕上找不到的内容:(我知道这样做的方法,但我正在尝试创建更多动态单元格,并通过NIB中分配的键/值对设置单元格的值。我只是不知道如何在UITableCell子类中查找UILabel,而不仅仅是查找UITableViewCellContentView。您不需要查找它们。只需添加自定义单元格函数即可这将使用nsstring并将其设置为您的标签。我的答案中哪一部分您难以理解?我将指定它