0

Facebook ページの Json フィードをテーブル ビューに解析しようとしていて、このチュートリアルに従っ ていると、次のエラーが発生します。 : オブジェクトを nil にすることはできません'"

私のtableview.hからのコードは次のとおりです。

    #import "FBViewController.h"
    @interface FBViewController ()
    {
    NSMutableData *fbdata;
    NSMutableArray *array;
    }

    @end

    @implementation FBViewController


    - (void)viewDidLoad
    {
    [super viewDidLoad];
    [[self fbtableview]setDelegate:self];
    [[self fbtableview]setDataSource:self];
    array = [[NSMutableArray alloc]init];

    NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/XXXXXXX/posts?access_token=ACCESS_TOKEN"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    connection = [NSURLConnection connectionWithRequest:request delegate:self];

    if (connection) {
    fbdata=[[NSMutableData alloc]init];
    }
    }


    - (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    }


    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
    [fbdata setLength:0];
    }


    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
    [fbdata appendData:data];
    }


    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
    NSLog(@"fail with error");
    }

    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
    NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:fbdata options:0 error:nil];
    NSArray *arraydata = [allDataDictionary objectForKey:@"data"];//objectforkey corresponde ao nome do dicionario


    for (NSDictionary *diction in arraydata)
    {
    NSString *message =[diction objectForKey:@"message"];

    [array addObject:message];
    [[self fbtableview]reloadData];
    }
    }


    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 1;
    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return [array count];
    }


    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell)
    {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.text = [array objectAtIndex:indexPath.row];
    return cell;
    }
    @end

誰でも私を助けることができますか?

4

1 に答える 1

0

問題はここにあると思います、

for (NSDictionary *diction in arraydata)
    {
    NSString *message =[diction objectForKey:@"message"];

    [array addObject:message]; //here some value is nil means you are trying to add a nil object to array that's why app getting crashed.
    [[self fbtableview]reloadData];
    }
    }
于 2013-05-02T04:16:22.470 に答える