具有多个帐户或用户的Xcode实时新闻Feed

时间:2014-08-16 13:22:55

标签: facebook facebook-graph-api xcode5 news-feed

我是xcode的新手。 我在桌面视图中创建了这个facebook,twitter,Instagram和youtube新闻源

起初我正在尝试这个Facebook加载多个json

#import "ViewController.h"
#import "DetailViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>


#define kQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define kJSONUrl [NSURL URLWithString:@"https://www.facebook.com/feeds/page.php?id=1387524391527078&format=json"]
#define kJSONUrl1 [NSURL URLWithString:@"https://www.facebook.com/feeds/page.php?id=196934133652011&format=json"]
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)



@interface ViewController ()

@end

@implementation ViewController
@synthesize jsonTitles,table,jsonContent;





-(void)loadJSON:(NSData *)responseData {

NSError *error;
NSArray *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

NSArray *array = [json valueForKey:@"entries"];

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

    NSArray *entry = [array objectAtIndex:i];

    NSString *title = [entry valueForKey:@"title"];
    NSString *content = [entry valueForKey:@"content"];


    [jsonTitles addObject:title];
    [jsonContent addObject:content];


}


[self.table reloadData];


}


- (void)viewDidLoad
{
self.table.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
jsonTitles = [[NSMutableArray alloc]init];
jsonContent = [[NSMutableArray alloc]init];


dispatch_async(kQueue, ^{
    NSData *data = [NSData dataWithContentsOfURL:kJSONUrl];
    [self performSelectorOnMainThread:@selector(loadJSON:) withObject:data waitUntilDone:YES];


    NSData *data1 = [NSData dataWithContentsOfURL:kJSONUrl1];
    [self performSelectorOnMainThread:@selector(loadJSON:) withObject:data1 waitUntilDone:YES];


});



[super viewDidLoad];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

return 40;


}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


return [jsonTitles count];

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[self performSegueWithIdentifier:@"detailSegue" sender:nil];
// NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"detailSegue" ascending:YES];



}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"detailSegue"]) {

    DetailViewController *detail = segue.destinationViewController;

    NSIndexPath *path = [self.table indexPathForSelectedRow];

    detail.titleText = [jsonTitles objectAtIndex:path.row];
    detail.contentText = [jsonContent objectAtIndex:path.row];




}


}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {





static NSString *tableCellID = @"tableCellID";

// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableCellID];

UITableViewCell *cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                        reuseIdentifier:tableCellID];




NSString *myurl = @"http://graph.facebook.com/idoltap/picture";
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myurl]];
UIImage *myimage = [[UIImage alloc] initWithData:imageData];

cell.imageView.image = myimage;


// cell.imageView.image = [UIImage imageNamed:@"background.png"];
cell.textLabel.text = @"iDOLTap";

if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableCellID];


}

cell.detailTextLabel.text = [jsonTitles objectAtIndex:indexPath.row];
if ([cell.detailTextLabel.text  isEqual: @" "]) {

    cell.detailTextLabel.text = [jsonContent objectAtIndex:indexPath.row];
}




return cell;
}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

我的模式是否正确? 我不知道如何为每个json /用户加载正确的个人资料图片,并按发布日期对其进行排序。 我只想帮助以正确的方式解决这个问题。

0 个答案:

没有答案