我是Tapku的新手,但我认为这可能是一个错误:
我一直在搜索代码,试图在某些时候发现它是否是我的错,但却找不到任何线索......
非常感谢您的帮助。 谢谢
更新代码:
TapkuCalendarViewController.h
#import <TapkuLibrary/TKCalendarMonthTableViewController.h>
@interface TapkuCalendarViewController : TKCalendarMonthTableViewController
@end
TapkuCalendarViewController.m
#import "TapkuCalendarViewController.h"
#import "EventKitController.h"
@implementation TapkuCalendarViewController
- (void) viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Today"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(selectTodayDate)];
[self.monthView selectDate:[NSDate date]];
}
- (void)selectTodayDate {
[self.monthView selectDate:[NSDate date]];
}
#pragma mark MonthView Delegate & DataSource
- (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate {
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit
fromDate:startDate
toDate:lastDate
options:NSWrapCalendarComponents];
NSInteger numberOfDays = components.day +1;
NSMutableArray *array = [NSMutableArray arrayWithCapacity:numberOfDays];
NSDate *day = startDate;
for (int x = 0; x<numberOfDays; x++) {
if ([[EventKitController listOfEventkitEventsAtDay:day] count] != 0) [array addObject:[NSNumber numberWithBool:YES]];
else [array addObject:[NSNumber numberWithBool:NO]];
if (x < numberOfDays-1) day = [day dateByAddingOneDay]; // private category method
}
assert([day isEqualToDate:lastDate]);
return array;
}
- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)newDate {
[self.tableView reloadData];
}
#pragma mark UITableView Delegate & DataSource
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSDate *dateSelected = self.monthView.dateSelected;
if (dateSelected == nil) return 0;
else return [[EventKitController listOfEventkitEventsAtDay:dateSelected] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *const CELL_ID = @"TapkuCalendarCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELL_ID];
if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CELL_ID];
EKEvent *event = [[EventKitController listOfEventkitEventsAtDay:self.monthView.dateSelected] objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", event.startDate, event.title];
cell.detailTextLabel.text = event.location;
return cell;
}
@end
答案 0 :(得分:0)
我认为这里存在问题:
- (void) _tileSelectedWithData:(NSArray*)ar{
在TKCalendarMonthView.m内部
通常情况下,如果未发生月份更改,则会调用此方法:
[self.delegate calendarMonthView:self didSelectDate:[self dateSelected]];
但是,如果确实发生了月份更改,则不会调用此方法,并且不会更新相关的表视图数据。添加对此方法的调用可以解决此问题。
答案 1 :(得分:0)
我认为这是一个错误。
didSelectDate:
在月份更改期间被调用为正常,但月视图的所选日期属性将被清除。所以它会重新加载表视图,但是当它到达
NSDate *dateSelected = self.monthView.dateSelected;
self.monthView.dateSelected
为nil
,导致您的空表。
解决方案:我已经在
结束时跟踪了最后选择的日期。 - (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)newDate
然后在表视图数据源方法中使用此lastSelectedDate
变量。选择更改月份的天数时,表格视图会显示正确的数据(如您的示例)。