2013-02-12 72 views
2

我正在尝试将Tapku日历添加到我的应用程序。我使用故事板,我添加了Tapku库,导入了必要的文件并添加了TKCalendarMonthViewDelegate方法。我将日历添加到名为calendarView的UIView中。当我运行应用程序时,日历不会出现,只是没有任何内容的视图。将Tapku日历添加到应用程序

-(void)viewDidLoad 
{ 
[super viewDidLoad]; 
[self.navigationController setNavigationBarHidden:NO animated:YES]; 

self.navigationItem.hidesBackButton = YES; 
calendar = [[TKCalendarMonthView alloc] init]; 
calendar.delegate = self; 
calendar.dataSource = self; 
calendar.frame = CGRectMake(0, 0, calendar.frame.size.width, calendar.frame.size.height); 

// Ensure this is the last "addSubview" because the calendar must be the top most view layer 
[self.view addSubview:calendar]; 
[calendar reload]; 

// Do any additional setup after loading the view. 
} 

任何人都可以帮助我吗?

+0

http://developinginthedark.com/posts/iphone-tapku-calendar-markers – iPatel 2013-02-12 14:26:24

+0

我已经使用过这个例子,我正努力将其添加到我的项目中 – 2013-02-12 15:39:09

+0

TapKu是否在xcode 5中工作 – 2014-10-16 13:24:09

回答

2

尝试通过直接specifing帧点,这样

calendar.frame = CGRectMake(0, 0, 320,400); 
1

如果要添加TKCalendarMonthView用故事板视图控制器,那么你不应该也被初始化TKCalendarMonthView的另一个实例在您的视图控制器 - viewDidLoad方法。

在你的故事板:

  • 添加TKCalendarMonthView到您的视图控制器。
  • 设置大小限制。
  • 将TKCalendarMonthView连接到视图控制器中的插座(请参见下文)。

在您的视图控制器:

添加一个出口的TKCalendarMonthView。

@interface YourViewController() <TKCalendarMonthViewDataSource, TKCalendarMonthViewDelegate> 
@property (weak, nonatomic) IBOutlet TKCalendarMonthView *calendarMonthView; 
@end 

在-viewDidLoad中,连接TKCalendarMonthView的委托和数据源。请注意,你也可以做到这一点的故事板,如果你第一次添加的注释IBOutlet中的委托和DataSource属性在TKCalendarMonthView.h

@implementation YourViewController 
... 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
... 
    self.calendarMonthView.delegate = self; 
    self.calendarMonthView.dataSource = self; 

但是这些变化本身不会得到TKCalendarMonthView显示日历。原因是该视图是由Storyboard初始化的,但是在由Storyboard加载时,没有任何现有的-init方法被调用。所以你需要添加一个-initWithCoder:方法到TKCalendarMonthView.m。以下示例将调用default -init:方法。

-(id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [self init]; 
    if (self) { 

    } 

    return self; 
} 

如果你这样做了,你应该看到渲染日历而不是空白视图。