我想使用kal日历框架。但我不知道如何将其实现到tabbar应用程序中。当我看一下如何初始化kalViewController的演示时,它看起来像这样。
-(void)viewDidLoad{
KalViewController *calendar = [[KalViewController alloc] init];
[self.navigationController pushViewController:calendar animated:YES];
}
这有效,但它转向另一种观点。我希望它使用故事板在同一视图中显示。
答案 0 :(得分:2)
我检查了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控制器将其连接起来并且工作正常。
我创建了一个示例项目: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;
}
我创建了一个分支来修复此问题并发布了pull-request。