KalViewControllerクラスを確認しました。実装はなくinitWithCoder:
、nibs/storyboardsからインスタンス化された場合に呼び出されるイニシャライザーです。
私はそれを機能させるためにこれを追加しました:
-(id)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder])) {
NSDate *date = [NSDate date];
logic = [[KalLogic alloc] initForDate:date];
self.initialDate = date;
self.selectedDate = date;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(significantTimeChangeOccurred) name:UIApplicationSignificantTimeChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:KalDataSourceChangedNotification object:nil];
}
return self;
}
UIViewControllerをstorybordステージにドラッグし、インスペクターのクラスをKalViewControllerに変更し、タブバーコントローラーから配線すると、機能しました。
サンプルプロジェクトを作成しました:TabbedKalTest @ GitHub
もちろん、DRYを念頭に置く必要があります。
-(void) _configureWithDate:(NSDate *)date
{
logic = [[KalLogic alloc] initForDate:date];
self.initialDate = date;
self.selectedDate = date;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(significantTimeChangeOccurred) name:UIApplicationSignificantTimeChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:KalDataSourceChangedNotification object:nil];
}
//called if created by nib/storyboard
-(id)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder])) {
[self _configureWithDate:[NSDate date]];
}
return self;
}
//the designated initializer for non-nib/storyboard creation
- (id)initWithSelectedDate:(NSDate *)date
{
if ((self = [super init])) {
[self _configureWithDate:date];
}
return self;
}
Kalでこれを修正するためのブランチを作成し、プルリクエストを投稿しました。