如何在ios中增加日历中的月份和年份

时间:2015-02-24 07:09:52

标签: ios objective-c calendar increment

我正在尝试从日历中增加日期和年份,但它只增加一个值,这意味着(它从jan增加到feb,但是在feb之后没有递增)我的要求是增加到12个月并且还同时一年必须增加。你能告诉我如何解决这个问题这是我的代码

- (IBAction)right:(id)sender {


    [datearray removeAllObjects];
    NSCalendar *cal = [NSCalendar currentCalendar];
    date = [cal dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:[NSDate date] options:0];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MMM YYYY"];
    NSString *stringFromDate = [formatter stringFromDate:date];
    yar.text=stringFromDate;
    NSString *y1=yar.text;
    NSArray * arr = [y1 componentsSeparatedByString:@" "];
    NSString *m=arr[0];
    NSString *yy=arr[1];


    spinner =  [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    spinner.mode = MBProgressHUDModeCustomView;

    [spinner setLabelText:@"Loading....."];

    [spinner setLabelFont:[UIFont systemFontOfSize:15]];

    [spinner show:YES];

    //[self.coutweek setText:[NSString stringWithFormat:@"%d",week]];
    NSString *urlString = [NSString stringWithFormat:@"http://edvancepreschoolsadminpanel.com/viverobranch/json/json_lunch.php?key=agile89rise98&food=%@&month=%@&year=%@&username=%@",scl,m,yy,temp];


    NSLog(@"the url string==%@",urlString);
    NSURL *url = [NSURL URLWithString:urlString];

    NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

    NSLog(@"the str==%@",jsonString);

    NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];

    NSLog(@"%@",results);

    luncharray = [[NSMutableArray alloc]init];
    NSArray *array=[results objectForKey:@"lunch_menu"];



    for (int i=0; i<[array count]; i++) {

        NSString *dat =[[array objectAtIndex:i]objectForKey:@"date"];
        NSString *mon =[[array objectAtIndex:i]objectForKey:@"month"];
        NSString *yea =[[array objectAtIndex:i]objectForKey:@"year"];
        NSString *luh =[[array objectAtIndex:i]objectForKey:@"food"];
        NSString *tim =[[array objectAtIndex:i]objectForKey:@"time"];

        ipadlunch *myimg =[[ipadlunch alloc]initWithdat:dat andmon:mon andyea:yea andlunch:luh andtime:tim];
        NSLog(@"%@",myimg);
        [luncharray addObject:myimg];
        // NSLog(@"the field==%@",videoarray1);
    } 

0 个答案:

没有答案