作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用了 Storyboard和 ios 9,Xcode 7.2,在这个项目中使用了日历 View 和通过网络服务器获取数据的事件显示。我添加了日历工具包框架,还有两个文件添加我的项目,第一个是 CKDemoViewController.h,第二个是 CKDemoViewController.m,这次创建一个静态事件。但我想创建一个动态事件。那怎么可能。我尝试了很多次,但无法创建动态事件。怎么可能,请帮忙,谢谢。
#import "CKDemoViewController.h"
#import "NSCalendarCategories.h"
#import "NSDate+Components.h"
@interface CKDemoViewController () <CKCalendarViewDelegate, CKCalendarViewDataSource>
{
NSArray*date;
NSArray*title;
NSArray*img;
NSArray*des;
NSArray*evnt_ary;
NSArray*timeary;
}
@property (nonatomic, strong) NSMutableDictionary *data;
@end
@implementation CKDemoViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_event.php"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
self.data = [[NSMutableDictionary alloc] init];
[self setDataSource:self];
[self setDelegate:self];
// An event for the new MBCalendarKit release.
NSString *title = NSLocalizedString(@"Release MBCalendarKit 2.2.4", @"");
NSDate *date = [NSDate dateWithDay: 12 month:11 year:2016];
CKCalendarEvent *releaseUpdatedCalendarKit = [CKCalendarEvent eventWithTitle:title andDate:date andInfo:nil];
// An event for the new Hunger Games movie.
NSString *title2 = NSLocalizedString(@"The Hunger Games: Mockingjay, Part 1", @"");
NSDate *date2 = [NSDate dateWithDay:21 month:11 year:2014];
CKCalendarEvent *mockingJay = [CKCalendarEvent eventWithTitle:title2 andDate:date2 andInfo:nil];
// Integrate MBCalendarKit
NSString *integrationTitle = NSLocalizedString(@"Integrate MBCalendarKit", @"");
NSDate *integrationDate = date2;
CKCalendarEvent *integrationEvent = [CKCalendarEvent eventWithTitle:integrationTitle andDate:integrationDate andInfo:nil];
// An event for the new MBCalendarKit release.
NSString *title3 = NSLocalizedString(@"Fix bug where events don't show up immediately.", @"");
NSDate *date3 = [NSDate dateWithDay:29 month:11 year:2014];
CKCalendarEvent *fixBug = [CKCalendarEvent eventWithTitle:title3 andDate:date3 andInfo:nil];
self.data[date] = @[releaseUpdatedCalendarKit];
self.data[date2] = @[mockingJay, integrationEvent];
self.data[date3] = @[fixBug];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[response appendData:data];
NSLog(@"error receving data %@",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray *results = [json objectForKey:@"status"];
title = [[results valueForKey:@"event"]valueForKey:@"event_title"];
NSLog(@"event name fetch %@",title);
date =[[results valueForKey:@"event"]valueForKey:@"event_date"];
NSLog(@"event fetch %@",date);
img =[[results valueForKey:@"event"]valueForKey:@"img"];
des =[[results valueForKey:@"event"]valueForKey:@"event_detail"];
evnt_ary =[[results valueForKey:@"event"]valueForKey:@"event_name"];
timeary =[[results valueForKey:@"event"]valueForKey:@"event_time"];
}
#pragma mark - CKCalendarViewDataSource
- (NSArray *)calendarView:(CKCalendarView *)calendarView eventsForDate:(NSDate *)date
{
return [self data][date];
}
#pragma mark - CKCalendarViewDelegate
// Called before/after the selected date changes
- (void)calendarView:(CKCalendarView *)CalendarView willSelectDate:(NSDate *)date
{
}
- (void)calendarView:(CKCalendarView *)CalendarView didSelectDate:(NSDate *)date
{
}
// A row is selected in the events table. (Use to push a detail view or whatever.)
- (void)calendarView:(CKCalendarView *)CalendarView didSelectEvent:(CKCalendarEvent *)event
{
}
@end
最佳答案
请参阅此链接以获取代码,仅一个事件设置另一个您的逻辑:
关于ios - 如何在 MBCalendarKit 中通过 JSON 添加事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38434923/
我是一名优秀的程序员,十分优秀!