Я пытаюсь создать пользовательский UIView (.h .m & .xib) для заголовка раздела UITableView.Unrecognized Selector - Пользовательские заголовки секции UITableView
Цель состоит в том, что я могу передать заглавию, используя следующую строку:
sectionHeaderView.sectionLabel.text = @"SOME TEXT";
Однако это всегда вызывает следующее сообщение об ошибке:
[UIView sectionLabel]: unrecognized selector sent to instance 0x6d3f6f0
Почему это думать, что это UIView, когда Я объявляю его DUSettingsSectionView? Вот код. Надеюсь, кто-то может указать мне в правильном направлении.
==== ==== КОД
Из моего 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
Попробуйте 'NSLog (@" Nib:% @ ", nibArray);' в 'initWithFrame:', чтобы увидеть, что он думает, что загружается. –