iPhone標準のカレンダーのようなものをつくりたいときに、Kal Calendarというコンポーネントを使用しました。
そこで、今回は選択した日付に関連したデータをカレンダーの下のテーブルビューセルに表示させる方法を記載します。
クラス:KalViewController.m
- (void)loadView
{
if (!self.title) self.title = @"Calendar";
KalView *kalView = [[[KalView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] delegate:self logic:logic] autorelease];
self.view = kalView;
tableView = kalView.tableView;
tableView.dataSource = detaSource;
tableView.delegate = delegate;
[tableView retain];
[kalView selectDate:[KalDate dateFromNSDate:self.initialDate]];
[self reloadData];
}
に
detaSource = [SimpleKalDataSource dataSource]; [detaSource retain];
を追加してください。これで下のテーブルビューセルにアクセスできます。
次に、SimpleKalDataSourceを変更します。
ViewDataSource.m
@implementation SimpleKalDataSource
{
NSArray* array_;
}
まずはメンバ変数を定義します。
次に、下のテーブルビューセルに表示させたい値を配列に格納します。
- (void)loadItemsFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate
{
array = [NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];
}
あとは、配列の中身によって表示が変わるよう以下を設定してあげます。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
どうしてもできない場合は、KalViewControllerの
UITableViewDelegateのdelegate KalDataSourceのdataSource
の値を見てください。
retain忘れずに。
最後に、
removeAllItems
日付が変更されたときに、データを削除します。
適宜削除の処理を書きましょう。
参考URL:
http://www.andyshep.org/2011/05/01/calendar-control-on-ios.html
http://stackoverflow.com/questions/12111309/kal-calendar-walkthrough
