无法识别的选择器-自定义UITableView节标题

无法识别的选择器-自定义UITableView节标题,uitableview,header,unrecognized-selector,Uitableview,Header,Unrecognized Selector,我正在尝试为UITableView节头创建自定义UIView(.h.m&.xib) 目的是我可以使用以下行传递标题标题: sectionHeaderView.sectionLabel.text = @"SOME TEXT"; 但是,这始终会导致以下错误: [UIView sectionLabel]: unrecognized selector sent to instance 0x6d3f6f0 当我将它声明为DUSettingsSectionView时,为什么它认为这是一个UIView?这

我正在尝试为UITableView节头创建自定义UIView(.h.m&.xib)

目的是我可以使用以下行传递标题标题:

sectionHeaderView.sectionLabel.text = @"SOME TEXT";
但是,这始终会导致以下错误:

[UIView sectionLabel]: unrecognized selector sent to instance 0x6d3f6f0
当我将它声明为DUSettingsSectionView时,为什么它认为这是一个UIView?这是代码。希望有人能给我指出正确的方向

==代码====

从我的UIViewController

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 16;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
DUSettingsSectionView *sectionHeaderView = [[DUSettingsSectionView alloc] init];
//    sectionHeaderView.sectionLabel.text = @"SOME TEXT";
return sectionHeaderView;
}
从DUSettingsSectionView.h

#import <UIKit/UIKit.h>
@interface DUSettingsSectionView : UIView {
    UILabel *sectionLabel;
}
@property (nonatomic, strong) IBOutlet UILabel *sectionLabel;
@end

sectionLabel在.xib内部完全连接,.xib被设置为DUSettingsSectionView类。

似乎您在DUSettingsSectionView的
initWithFrame:
方法内部加载了.xib,但您调用了
init
内部
(UIView*)tableView:(UITableView*)tableView for HeaderInSection:(NSInteger)部分
要修复此问题,请将
(UIView*)tableView:(UITableView*)tableView view for headerinsection:(NSInteger)section
更改为类似以下内容:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  DUSettingsSectionView *sectionHeaderView = [[DUSettingsSectionView alloc] initWithFrame:frame];
  sectionHeaderView.sectionLabel.text = @"SOME TEXT";
  return sectionHeaderView;
}

您在
视图ForHeaderInSection:
方法中显示了注释掉的赋值…这就是导致错误的赋值吗?是的,如果我取消对赋值行的注释,则会收到以下错误:-[UIView sectionLabel]:发送到实例0x6d3f6f0 2012-06-23 15:36:13.891 du[4108:207]的无法识别的选择器***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[UIView sectionLabel]:发送到实例0x6d3f6f0的无法识别的选择器'Try
NSLog(@“Nib:%@”,NIBRARY)initWithFrame:
中查看它认为正在加载的内容。Nib:(“”)正确…因此它不会将Nib的主视图视为自定义类的对象(我猜下面的注释解释了这一点)。使用initWithFrame:Nib:(“”)2012-06-23 16:16:15.801 du[4545:207]后仍然存在相同的问题-[UIView sectionLabel]:发送到实例0x6d54d40 2012-06-23 16:16:15.802 du[4545:207]***的无法识别的选择器由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[UIView sectionLabel]:无法识别的选择器发送到实例0x6d54d40'修复:非常抱歉,伙计们。问题纯粹是由于界面生成器造成的。我与“文件的所有者”建立了连接。一旦我删除了这些并通过视图重新建立了连接,一切正常。然后NIB被正确加载。感谢有用的指针。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  DUSettingsSectionView *sectionHeaderView = [[DUSettingsSectionView alloc] initWithFrame:frame];
  sectionHeaderView.sectionLabel.text = @"SOME TEXT";
  return sectionHeaderView;
}