NSDATE/NSCALENDAR问题
-
30-09-2019 - |
题
我的应用程序中有以下代码。它是一个iPad应用程序,在一个名为Mottable,Tuetable的单个视图中,有五个桌子。这些桌子代表周一至周五。
在此代码中,我得到日期,并将每个表格设置为周一至周五(本周)的日期。然后,如果我按下按钮,nextweek将变为真,我会重新加载表数据。这意味着一周的增加。看?
-(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];
}
我的问题是,出于某种有线原因,它只会在下周七天增加7天,而当按下按钮任何想法时,其他日子都没有更改?谢谢。
解决方案
在NextWeekdown方法中,您只能重新加载蒙面 - 因此自然而然地不会重新加载。您还需要重新加载所有其他表...
不隶属于 StackOverflow