0

我尝试为我的日历使用自定义 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 天,任何人都可以举一个简单的例子来使用这个 3rd 方框架https://github.com/klazuka/Kal吗?repo 上的那个好像有点复杂,我只想用一个自定义的数据源。

4

1 回答 1

0

似乎cc_componentsForMonthDayAndYear您正在调用的函数null只是从调用函数的任何位置进行调试,并检查被调用的函数是否已打开NSDate并且未释放。

当崩溃发生时,您总是Enable Zombies可以找到释放的对象。NSZombieEnabled您可以通过设置为来跟踪是否有任何变量被释放YES。启用僵尸后,已释放对象的消息将不再表现异常或以难以理解的方式崩溃,而是会记录一条消息并以可预测和调试器可断点的方式死亡。您可以NSZombieEnabled通过以下步骤进行设置。

从上面的菜单栏中选择产品。按住 alt/option 并选择“测试...”或“运行...”。

1. 转到参数选项卡,并添加NSZombieEnabled YES“环境变量”部分。

或者

2. 转到诊断选项卡,并检查Enable Zombie Objects“内存管理”部分。

于 2013-08-30T06:06:39.060 回答