一個XIB文件,我想用一個XIB文件來定製Xcode的實現代碼如下部分(客觀C),這裏AR我的文件:使用自定義泰伯維節頭
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)。 希望得到任何幫助
謝謝,這是工作:) – Ali