2012-12-19 20 views
0

我想使用卡尔日历框架。但我不知道如何将这个实现到一个tabbar应用程序。当我查看如何初始化kalViewController的演示时,它看起来像这样。将卡尔日历应用于标签栏应用程序

-(void)viewDidLoad{ 
    KalViewController *calendar = [[KalViewController alloc] init]; 
    [self.navigationController pushViewController:calendar animated:YES]; 
} 

This works but it goes to another view。我希望它能够以相同的观点展示,使用故事板。

+0

所以我应该从我自己的viewController类中的KalViewController复制所有代码? – Steaphann

+0

好吧,这不会是最好的解决方案。但是你有什么建议呢? – Steaphann

+0

大声笑我知道的基本知识,我的问题是,我有一个导航控制器内的tabbar。我正在与故事板 – Steaphann

回答

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控制器有线它和它的工作。


我创建了一个样本项目:[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

+0

请参阅我的编辑 – vikingosegundo

+0

你是个天才!但是,你能简单地解释一下你在这里做什么吗?所以在将来我也可以写出这个神奇的代码! – Steaphann

+0

你的意思是在'initWithCoder:'? – vikingosegundo

相关问题