Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 自定义KalDataSource我试图实现它,但我';我犯了一个错误_Iphone_Ios_Objective C_Cocoa_Calendar - Fatal编程技术网

Iphone 自定义KalDataSource我试图实现它,但我';我犯了一个错误

Iphone 自定义KalDataSource我试图实现它,但我';我犯了一个错误,iphone,ios,objective-c,cocoa,calendar,Iphone,Ios,Objective C,Cocoa,Calendar,我尝试为我的日历使用自定义kal数据源。我成功地获取了数据,当我尝试运行它时,我一直收到以下错误: -[NSNull cc_componentsForMonthDayAndYear]: unrecognized selector sent to instance 0x2823fb8 我的代码 // KalParseDataSource.m #import "KalParseDataSource.h" #import <Parse/Parse.h> @implementatio

我尝试为我的日历使用自定义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
//KalParseDataSource.m
#导入“KalParseDataSource.h”
#进口
@ParseDataSource的实现
静态布尔值在结论之间(NSDate*日期,NSDate*开始,NSDate*结束)
{
return[日期比较:开始]!=传感器取消搜索&[日期比较:结束]!=传感器取消搜索;
}
-(id)init
{
if((self=[super init])){
items=[[NSMutableArray alloc]init];
events=[[NSMutableArray alloc]init];
}
回归自我;
}
#pragma标记UITableViewDataSource协议一致性
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*标识符=@“MyCell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:identifier];
如果(!单元格){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:标识符];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
cell.textlab.text=@“填充文本”;
返回单元;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回0;
}
-(无效)呈现日期从:(NSDate*)从日期到:(NSDate*)到日期委托:(id)委托{
NSLog(@“获取数据”);
如果([事件计数]>0){
[委托加载的数据源:self];
返回;
}
NSDateFormatter*fmt=[[NSDateFormatter alloc]init];
[fmt setDateFormat:@“yyyy-MM-dd hh:MM:ss”];
PFUser*user=[PFUser currentUser];
PFQuery*query=[PFQuery queryWithClassName:@“CalendarEvents”];
[查询whereKey:@“用户”等同于:用户];
[查询findObjectsInBackgroundWithBlock:^(NSArray*对象,NSError*错误){
如果(!错误){
[事件移除所有对象];
[events addObjectsFromArray:对象];
[委托加载的数据源:self];
}否则{
NSLog(@“Error:%@”,Error,[Error userInfo]);
}
}];
}
-(NSArray*)标记日期从:(NSDate*)从日期到:(NSDate*)到日期{
返回[[self tags from:fromDate to:toDate]valueForKeyPath:@“date”];
}
-(无效)加载项从日期:(NSDate*)从日期到日期:(NSDate*)到日期{
[items addObjectsFromArray:[self tags from:fromDate to:toDate];
}
-(NSArray*)标记从:(NSDate*)从日期到:(NSDate*)到日期
{
NSMutableArray*匹配=[NSMutableArray];
for(事件中的PFObject*事件){
if(IsDateBeween结论性([event objectForKey:@“event_date”]、fromDate、toDate)){
[匹配addObject:事件];
}
}
返回比赛;
}
-(无效)删除所有项目{
[项目移除所有对象];
}
@结束
保存日历的我的视图控制器

#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
#导入“MainMenuViewController.h”
#输入“Kal.h”
#导入“KalParseDataSource.h”
@接口MainMenuViewController()
@结束
@实现MainMenuViewController
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后执行任何其他设置。
id source=[[KalParseDataSource alloc]init];
KalViewController*日历=[[KalViewController alloc]init];
calendar.dataSource=source;
[自添加ChildViewController:日历];
[日历didMoveToParentViewController:self];
[self.view addSubview:calendar.view];
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束

我被这个问题困扰了三天,有人能举个简单的例子来说明如何使用这个第三方框架吗?回购协议上的那个似乎有点复杂,我只想使用一个自定义数据源。

似乎您使用
null
调用的函数
cc\u组件的日期和年份都是
null
只要在调用函数的任何位置进行调试,然后检查被调用的函数是否在
NSDate
上,并且没有发布

而且,当崩溃发生时,您始终可以
启用僵尸
来查找释放的对象。您可以通过将
NSZombieEnabled
设置为
YES
来跟踪是否释放了任何变量。启用僵尸后,释放对象的消息将不再以难以理解的方式表现异常或崩溃,而是以可预测和可中断的方式记录消息并消亡。 您可以通过以下步骤设置
NSZombieEnabled

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

一,。 转到Arguments选项卡,并在“环境变量”部分添加
NSZombieEnabled
YES

二,。
转到诊断选项卡,并在“内存管理”部分选中启用僵尸对象。

或者,比这两种方法更好的是,在Instruments的僵尸模板下运行应用程序。这将为您提供比调试器更多的信息。