我正在尝试为UITableView节头创建一个自定义UIView(.h .m & .xib)。无法识别的选择器 - 自定义UITableView节头
的目的是,我可以使用下面的行通过标题标题:
sectionHeaderView.sectionLabel.text = @"SOME TEXT";
然而,这总是会引起以下错误:
[UIView sectionLabel]: unrecognized selector sent to instance 0x6d3f6f0
它为什么会认为这是一个UIView时我声明它为DUSettingsSectionView?这是代码。希望有人能指出我正确的方向。
==== ==== CODE
从我的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
从DUSettingsSectionView.m
#import "DUSettingsSectionView.h"
@implementation DUSettingsSectionView
@synthesize sectionLabel;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"DUSettingsSectionView" owner:self options:nil];
self = [nibArray objectAtIndex:0];
}
return self;
}
@end
sectionLabel已满y连接到.xib中,并将.xib设置为DUSettingsSectionView类。
您展示在注释掉的分配你的'viewForHeaderInSection:'方法...是导致错误的那个吗? –
是的,如果我取消注释赋值行然后我收到以下错误: - [UIView sectionLabel]:无法识别的选择器发送到实例0x6d3f6f0 2012-06-23 15:36:13.891 du [4108:207] ***终止应用程序由于未捕获异常'NSInvalidArgumentException',原因:' - [UIView sectionLabel]:无法识别的选择器发送到实例0x6d3f6f0' – Richard
尝试'initWithFrame:'中的NSLog(@“Nib:%@”,nibArray);'它认为正在加载。 –