У меня есть следующий код в моем приложении.Это приложение для iPad, с пятью таблицами в одном представлении с именами monTable, tueTable и т. Д. Эти таблицы представляют собой понедельник - пятницу.
В этом коде я получаю дату и устанавливаю название каждой таблицы на дату с понедельника по пятницу (на этой неделе).Затем, если я нажимаю кнопку nextWeek становится TRUE, и я перезагружаю данные таблицы.Это означает, что неделя увеличивается.Видите?
-(IBAction)nextWeekDown{
nextWeek = TRUE;
[monTable reloadData];
}
- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section{
curDate = [NSDate date]; // Get current date
calendar = [NSCalendar currentCalendar];// Init calendar
comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate]; // Get necessary date components
// Week days change from 1 to 7, Sunday is the 1st, Saturday - the last one.
if (tableView == monTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:2];
}
}
if (tableView == tueTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:3];
}
}
if (tableView == wedTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:4];
}
}
if (tableView == thuTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:5];
}
}
if (tableView == friTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:6];
}
}
NSDate *tDate = [calendar dateFromComponents:comps];
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"EEE, MMM d"];
return [formatter stringFromDate:tDate];
}
Моя проблема в том, что по какой-то проводной причине он увеличивается только с понедельника на семь дней до следующей недели, и ни один из других дней не изменяется при нажатии кнопки, есть идеи?Спасибо.