2010-02-23 50 views
0

我希望用戶輸入一行到表中...並自動創建一個表格節的行,它被添加的一天,並保持它在白天的順序..部分當前可用日期?

又名用戶添加了一行今天表...把它放在02月22日在...明天他們將增加一個單元投入了它在創造另一段2月23日,行添加到它

+0

這是一個iPhone應用程序 – brent 2010-02-23 21:19:08

回答

0
this will help... 

today = [NSDate date]; 
dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"MM/dd/yyyy :EEEE"]; 
dateString = [dateFormat stringFromDate:today]; 
NSLog(@"date: %@", dateString); 
[dateFormat release]; 
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
components = [gregorian components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today]; 

[組件setDay:([成分日] - ([元件周​​日] -2))];

NSDate *lastDayofweek = [gregorian dateFromComponents:components1]; 
NSDateFormatter *dateFormat_last = [[NSDateFormatter alloc] init]; 
[dateFormat_last setDateFormat:@"MMMM d,yyyy"]; 
NSString *dateString_last = [dateFormat_last stringFromDate:lastDayofweek]; 
[dateFormat_last autorelease]; 
NSDate *beginningOfWeek = [gregorian dateFromComponents:components]; 
NSDateFormatter *dateFormat_first = [[NSDateFormatter alloc] init]; 
[dateFormat_first setDateFormat:@"MMMM d,yyyy"]; 
NSString *dateString_first = [dateFormat_first stringFromDate:beginningOfWeek]; 
[dateFormat_first autorelease];