Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UITableview按不同日期按节排序_Objective C_Json_Uitableview_Nsjsonserialization - Fatal编程技术网

Objective c UITableview按不同日期按节排序

Objective c UITableview按不同日期按节排序,objective-c,json,uitableview,nsjsonserialization,Objective C,Json,Uitableview,Nsjsonserialization,我正在使用JSON将共享谷歌日历中的事件输入我的应用程序。在某些日期有两个或两个以上的活动。如您所见,{gd$when},{startDate}下的日期格式很长(2013-04-28819:00:00.000+02:00)。 我需要每个部分都是dd-MM-yy格式的日期。然后cell.textlab.Text将是Title/$t,cell.detailtextlab.Text将是从gd$when/startTime开始的时间(hh:MM)。我只想显示那些等于或晚于今天日期的部分 为了配合rayw

我正在使用JSON将共享谷歌日历中的事件输入我的应用程序。在某些日期有两个或两个以上的活动。如您所见,{gd$when},{startDate}下的日期格式很长(2013-04-28819:00:00.000+02:00)。 我需要每个部分都是dd-MM-yy格式的日期。然后cell.textlab.Text将是Title/$t,cell.detailtextlab.Text将是从gd$when/startTime开始的时间(hh:MM)。我只想显示那些等于或晚于今天日期的部分

为了配合raywenderlich.com上的教程,我对它进行了研究。我现在的代码是这样的,但我还没有将其实现到tableviewcontroller中

#define kBgQueue dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

#define googleURL [NSURL URLWithString: @"http://www.google.com/calendar/feeds/kao1d80fd2u5kh7268caop11o4%40group.calendar.google.com/public/full?alt=json"]

#import "ViewController.h"

@interface ViewController () {
    IBOutlet UILabel* humanReadble;
    IBOutlet UILabel* jsonSummary;
}

@end

@implementation ViewController

-(void)viewDidLoad
{
    [super viewDidLoad];
    dispatch_async(kBgQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL:googleURL];

        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    });
}

- (void)fetchedData:(NSData *)responseData {
    //parse out the JSON data
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    NSArray* feed = [json valueForKeyPath:@"feed.entry"];
    NSLog(@"feed: %@", feed);
    for (int i=0; i<[feed count]; i++) {
        NSDictionary* event = [feed objectAtIndex:i];
        NSString* eventTitle = [event valueForKeyPath:@"title.$t"];
            NSLog(@"Title: %@", eventTitle);
    }
}

@end
#定义kBgQueue调度(获取)全局(调度(队列)优先级(默认值为0)
#定义Google URL[NSURL URLWithString:@”http://www.google.com/calendar/feeds/kao1d80fd2u5kh7268caop11o4%40group.calendar.google.com/public/full?alt=json"]
#导入“ViewController.h”
@界面视图控制器(){
IBUILabel*人性可读;
IBUILabel*jsonSummary;
}
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
调度异步(kBgQueue^{
NSData*data=[NSData dataWithContentsOfURL:googleURL];
[self-performSelectorOnMainThread:@selector(fetchedData:)with object:data waitUntilDone:YES];
});
}
-(void)获取数据:(NSData*)响应数据{
//解析出JSON数据
n错误*错误;
NSDictionary*json=[NSJSONSerialization JSONObject WithData:responseData选项:针织错误:&错误];
NSArray*feed=[json valueForKeyPath:@“feed.entry”];
NSLog(@“feed:%@”,feed);

对于(int i=0;i其中,正如我的建议所说,当您获得日期数时,创建节数,并且在每个节中,您必须输入事件数,即每个节的行数。您将在

-(NSInteger)tableView:(UITableView*)tableView行数section:(NSInteger)section

在这之后,像这样放置每个标题的视图-

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
    headerView=[[UIView alloc] init];
    headerView.tag=section+1000;
    headerView.backgroundColor=[UIColor clearColor];


    UILabel *labelInHeader=[[UILabel alloc] init];
    labelInHeader.backgroundColor=[UIColor clearColor];

    labelInHeader.adjustsFontSizeToFitWidth=YES;
    labelInHeader.minimumScaleFactor=13.00;

    labelInHeader.textColor=[UIColor blackColor];
    labelInHeader.textAlignment=NSTextAlignmentCenter;
    labelInHeader.font=[UIFont fontWithName:FONTCENTURYGOTHICBOLD size:20.0];

    labelInHeader.frame=CGRectMake(30, 0, 229,47);
    labelInHeader.lineBreakMode=NSLineBreakByWordWrapping;
    labelInHeader.numberOfLines=2;

    [headerView addSubview:labelInHeader];
    return headerView;
}
希望这有帮助