2013-02-05 1 views
0

AFNetworking AFJSONRequestOperation으로 JSON 데이터를 구문 분석하려고합니다. 그러나 나는 어떤 이유로 든 비어있는 UITable을 얻고있다.AFNetworking으로 비어있는 UITable JSON 구문 분석

나는 AFNetworking없이 그것을 할 수 있었다.

사람은 당신이 1을 반환해야

  • numberOfSectionInTableView을 viewWillAppear 할 수있는 viewDidLoad에서 코드를 된 개시 이동해야 Google Drive

    #import "AFNetworking.h" 
    
    
        #import "AFJSONRequestOperation.h" 
    
        @interface KKViewController() 
    
        @end 
    
    @implementation KKViewController 
    
    @synthesize movies = _movies, count = _count; 
    
    
    - (id)initWithStyle:(UITableViewStyle)style 
    { 
        self = [super initWithStyle:style]; 
        if (self) { 
         // Custom initialization 
        } 
        return self; 
    } 
    
    - (void)viewDidLoad 
    { 
        [super viewDidLoad]; 
    
        self.movies = [[NSArray alloc] init]; 
    
        // get data from youtube 
    
    NSURL *url = [[NSURL alloc] initWithString:@"http://gdata.youtube.com/feeds/api/playlists/PL0l3xlkh7UnvLdr0Zz3XZZuP2tENy_qaP?v=2&alt=jsonc&max-results=50"]; 
    
        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; 
    
        AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 
    
    
    
         self.movies = [JSON valueForKeyPath:@"data.items.video"]; 
    
         // NSLog(@@, video) 
    
         // 
    
    
         self.count = [JSON valueForKeyPath:@"data.items.video.thumbnail"]; 
         [self.activityIndicatorView stopAnimating]; 
         [self.tableView setHidden:NO]; 
         [self.tableView reloadData]; 
    
        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { 
         NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); 
        }]; 
    
        [operation start]; 
    
    
    
    
    
        // Uncomment the following line to preserve selection between presentations. 
        // self.clearsSelectionOnViewWillAppear = NO; 
    
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
        // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    } 
    
    - (void)didReceiveMemoryWarning 
    { 
        [super didReceiveMemoryWarning]; 
        // Dispose of any resources that can be recreated. 
    } 
    
    #pragma mark - Table view data source 
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
    
        // Return the number of sections. 
        return 0; 
    } 
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
    
    
    
        // Return the number of rows in the section. 
    
        if (self.movies && self.movies.count) { 
         return self.movies.count; 
        } else { 
         return 0; 
        } 
    
    
    } 
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
        static NSString *cellID = @"Cell Identifier"; 
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; 
    
        if (!cell) { 
         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]; 
        } 
    
        NSDictionary *movie = [self.movies objectAtIndex:indexPath.row]; 
    
    
        NSDictionary *countt = [self.count objectAtIndex:indexPath.row]; 
        cell.textLabel.text = [movie objectForKey:@"title"]; 
        cell.detailTextLabel.text = [movie objectForKey:@"uploader"]; 
    
        NSURL *url = [[NSURL alloc] initWithString:[countt objectForKey:@"hqDefault"]]; 
        [cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]]; 
    
        return cell; 
    } 
    
    
    
    
    /* 
    // Override to support conditional editing of the table view. 
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        // Return NO if you do not want the specified item to be editable. 
        return YES; 
    } 
    */ 
    
    /* 
    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        if (editingStyle == UITableViewCellEditingStyleDelete) { 
         // Delete the row from the data source 
         [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
        } 
        else if (editingStyle == UITableViewCellEditingStyleInsert) { 
         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
        } 
    } 
    */ 
    
    /* 
    // Override to support rearranging the table view. 
    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
    { 
    } 
    */ 
    
    /* 
    // Override to support conditional rearranging of the table view. 
    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        // Return NO if you do not want the item to be re-orderable. 
        return YES; 
    } 
    */ 
    
    #pragma mark - Table view delegate 
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        // Navigation logic may go here. Create and push another view controller. 
        /* 
        <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 
        // ... 
        // Pass the selected object to the new view controller. 
        [self.navigationController pushViewController:detailViewController animated:YES]; 
        */ 
    } 
    
    @end 
    
    
        [1]: https://docs.google.com/folder/d/0B1EPIKZI6a5sSzVWdXh6VU1POWs/edit?usp=sharing 
    
  • 답변

    1
    1. 내 코드에서 참조하시기 바랍니다하지 0

    +0

    고맙습니다. :) – user1951876