我檢查了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,從使用TabBar控制器有線它和它的工作。
我創建了一個樣本項目:[email protected]
當然幹應該記住:
-(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;
}
我創建了分公司,在卡爾來解決這一問題,並張貼一個pull-request。
所以我應該從我自己的viewController類中的KalViewController複製所有代碼? – Steaphann
好吧,這不會是最好的解決方案。但是你有什麼建議呢? – Steaphann
大聲笑我知道的基本知識,我的問題是,我有一個導航控制器內的tabbar。我正在與故事板 – Steaphann