我的应用程序中有以下代码。这是一个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];
}我的问题是,由于某种网络原因,它只增加了周一到下周的七天,而当按下按钮时,其他日子都没有改变,有什么想法吗?谢谢。
发布于 2010-08-24 05:55:40
在nextWeekDown方法中,您只重新加载monTable -所以其他表自然不会重新加载。您还需要重新加载所有其他表...
https://stackoverflow.com/questions/3551634
复制相似问题