【问题标题】:Add Tapku calendar to app将 Tapku 日历添加到应用程序
【发布时间】:2013-02-12 14:20:48
【问题描述】:

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

-(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.
}

谁能帮帮我?

【问题讨论】:

标签: iphone ios calendar storyboard tapku


【解决方案1】:

尝试直接指定帧点,像这样

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

【讨论】:

    【解决方案2】:

    如果您使用 Storyboard 将 TKCalendarMonthView 添加到您的视图控制器,那么您也不应该在视图控制器的 -viewDidLoad 方法中初始化另一个 TKCalendarMonthView 实例。

    在您的故事板中:

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

    在您的视图控制器中:

    为 TKCalendarMonthView 添加一个出口。

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

    在-viewDidLoad中,连接TKCalendarMonthView的delegate和数据源。请注意,如果您首先将 IBOutlet 注释添加到 TKCalendarMonthView.h 中的委托和数据源属性,您也可以在 Storyboard 中执行此操作

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

    但是,仅这些更改不会使 TKCalendarMonthView 显示日历。原因是视图正在由 Storyboard 初始化,但在 Storyboard 加载时没有调用任何现有的 -init 方法。因此,您需要向 TKCalendarMonthView.m 添加一个 -initWithCoder: 方法。以下示例将调用默认的 -init: 方法。

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

    如果您执行所有这些操作,您应该会看到呈现的日历而不是空白视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-13
      • 1970-01-01
      相关资源
      最近更新 更多