我尝试使用自定义kal数据源作为我的日历。我成功获取了数据,当我尝试运行它时,我不断收到此错误:
-[NSNull cc_componentsForMonthDayAndYear]: unrecognized selector sent to instance 0x2823fb8
我的代码
// KalParseDataSource.m
#import "KalParseDataSource.h"
#import <Parse/Parse.h>
@implementation KalParseDataSource
static BOOL IsDateBetweenInclusive(NSDate *date, NSDate *begin, NSDate *end)
{
return [date compare:begin] != NSOrderedAscending && [date compare:end] != NSOrderedDescending;
}
- (id)init
{
if ((self = [super init])) {
items = [[NSMutableArray alloc] init];
events= [[NSMutableArray alloc] init];
}
return self;
}
#pragma mark UITableViewDataSource protocol conformance
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"MyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = @"Filler text";
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 0;
}
- (void)presentingDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id<KalDataSourceCallbacks>)delegate{
NSLog(@"getting data");
if ([events count] > 0) {
[delegate loadedDataSource:self];
return;
}
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
[fmt setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
PFUser *user = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@"CalendarEvents"];
[query whereKey:@"user" equalTo:user];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[events removeAllObjects];
[events addObjectsFromArray:objects];
[delegate loadedDataSource:self];
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
- (NSArray *)markedDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate {
return [[self tagsFrom:fromDate to:toDate] valueForKeyPath:@"date"];
}
- (void)loadItemsFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate {
[items addObjectsFromArray:[self tagsFrom:fromDate to:toDate]];
}
- (NSArray *)tagsFrom:(NSDate *)fromDate to:(NSDate *)toDate
{
NSMutableArray *matches = [NSMutableArray array];
for (PFObject *event in events){
if (IsDateBetweenInclusive([event objectForKey:@"event_date"], fromDate, toDate)){
[matches addObject:event];
}
}
return matches;
}
- (void)removeAllItems{
[items removeAllObjects];
}
@end
我的视图控制器持有日历。
#import "MainMenuViewController.h"
#import "Kal.h"
#import "KalParseDataSource.h"
@interface MainMenuViewController ()
@end
@implementation MainMenuViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
id<KalDataSource> source = [[KalParseDataSource alloc] init];
KalViewController *calendar = [[KalViewController alloc] init];
calendar.dataSource = source;
[self addChildViewController:calendar];
[calendar didMoveToParentViewController:self];
[self.view addSubview:calendar.view];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我坚持了3天,任何人都可以举出使用这个第三方框架https://github.com/klazuka/Kal的简单例子吗?回购中的那个似乎有点复杂,我只想使用自定义数据源。
答案 0 :(得分:0)
看起来你用cc_componentsForMonthDayAndYear
调用的函数null
只是在函数被调用的地方进行调试,并检查被调用的函数是否在NSDate
上并且它没有被释放。
当崩溃发生时,你总是可以Enable Zombies
找到释放的对象。您可以通过将NSZombieEnabled
设置为YES
来跟踪是否有任何变量被释放。启用僵尸后,释放对象的消息将不再出现奇怪的行为或以难以理解的方式崩溃,而是以可预测和调试器可破解的方式记录消息并死亡。
您可以按以下步骤设置NSZombieEnabled
。
从上面的菜单栏中选择产品。按住alt /选项并选择“测试...”或“运行...”。
1。
转到“参数”选项卡,然后在“环境变量”部分中添加NSZombieEnabled
YES
。
OR
2。
转到“诊断”选项卡,然后在“内存管理”部分中查看Enable Zombie Objects
。