0

我有一个带有按钮的主视图控制器,可将您带到日历视图(我正在使用 MBCalendarKit)。那和日历工作得很好。问题是当我尝试通过点击导航栏上的后退按钮从日历返回主视图时,应用程序崩溃。我得到的唯一消息是“线程 1:EXC_BAD_ACCESS(code=1, address=0xa000010)

这是我的代码:

#import "KFBCalendar.h"
#import "NSDate+Components.h"

@interface KFBCalendar ()
@property NSMutableDictionary* eventsDict;
@end

@implementation KFBCalendar

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

    CKCalendarView *calendar = [CKCalendarView new];

    [calendar setDelegate:self];
    [calendar setDataSource:self];

    [[self view]addSubview:calendar];

    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"MM/dd/yyyy HH:mm"];

    // NSMutableDictionary* eventsDict = [[NSMutableDictionary alloc] init];
    _eventsDict = [[NSMutableDictionary alloc] init];
    NSMutableArray* eventsArray = [[NSMutableArray alloc] init];

    CKCalendarEvent* aCKCalendarEvent = [[CKCalendarEvent alloc] init];
    aCKCalendarEvent.date = [dateformatter dateFromString: @"12/04/2013 07:15"];
    aCKCalendarEvent.title = @"Annual Meeting";
    [eventsArray addObject: aCKCalendarEvent];
    [_eventsDict setObject: eventsArray forKey: [NSDate dateWithDay:04 month:12 year:2013]];

    eventsArray = [[NSMutableArray alloc] init];
    aCKCalendarEvent = [[CKCalendarEvent alloc] init];
    aCKCalendarEvent.date = [dateformatter dateFromString: @"12/05/2013 13:30"];
    aCKCalendarEvent.title = @"Annual Meeting";
    [eventsArray addObject: aCKCalendarEvent];
    [_eventsDict setObject: eventsArray forKey: [NSDate dateWithDay:05 month:12 year:2013]];

    eventsArray = [[NSMutableArray alloc] init];
    aCKCalendarEvent = [[CKCalendarEvent alloc] init];
    aCKCalendarEvent.date = [NSDate dateWithDay:6 month:12 year: 2013];
    aCKCalendarEvent.title = @"Annual Meeting";
    [eventsArray addObject: aCKCalendarEvent];
    [_eventsDict setObject:eventsArray forKey:aCKCalendarEvent.date];
}

- (NSArray *)calendarView:(CKCalendarView *)calendarView eventsForDate:(NSDate *)date
{
    return [ self eventsDict][date];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

0 回答 0