xib ファイルを使用して、xcode (目的の C) で tableview セクションをカスタマイズしたかったのですが、ここに私のファイルがあります。
SectionHeaderView.xib は UILabel を持つ UIView です
SectionHeaderView.m
#import "SectionHeaderView.h"
@implementation SectionHeaderView
@synthesize sectionHeader;
@end
SectionHeaderView.h
#import <UIKit/UIKit.h>
@interface SectionHeaderView : UIView
{
IBOutlet UILabel *sectionHeader;
}
@property (nonatomic, strong) IBOutlet UILabel *sectionHeader;
@end
そして私のMasterViewController.mで
#import "SectionHeaderView.h"
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
SectionHeaderView *header = [[[NSBundle mainBundle] loadNibNamed:@"SectionHeaderView" owner:self options:nil] objectAtIndex:0];
return header;
}
ここまでは問題なく動作しますが、XIB ファイル所有者のカスタム クラスを「SectionHeaderView」に設定し、ラベルを「sectionHeader」に接続するとすぐに、エラー「NSUnknownKeyException」が発生します。これらを接続して、haeder を返す前に次のコードで label.text を変更できるようにしたかったのです。
header.sectionHeader.text = headerText;
MasterViewController にストーリーボード (xcode 4.5) を使用しています。助けていただければ幸いです