Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RootViewController.h
- #import "GDataYouTube.h"
- #import "GDataServiceGoogleYouTube.h"
- @interface RootViewController : UITableViewController {
- GDataFeedYouTubeVideo *feed;
- }
- @property (nonatomic, retain) GDataFeedYouTubeVideo *feed;
- @end
- ---------------------------------------------------------------------------------
- // RootViewController.m
- #import "RootViewController.h"
- @interface RootViewController (PrivateMethods)
- - (GDataServiceGoogleYouTube *)youTubeService;
- @end
- @implementation RootViewController
- @synthesize feed;
- - (void)viewDidLoad {
- NSLog(@"loading");
- GDataServiceGoogleYouTube *service = [self youTubeService];
- NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
- NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"annoyingorange"
- userFeedID:uploadsID];
- [service fetchFeedWithURL:feedURL
- delegate:self
- didFinishSelector:@selector(request:finishedWithFeed:error:)];
- [super viewDidLoad];
- }
- - (void)request:(GDataServiceTicket *)ticket
- finishedWithFeed:(GDataFeedBase *)aFeed
- error:(NSError *)error {
- self.feed = (GDataFeedYouTubeVideo *)aFeed;
- [self.tableView reloadData];
- }
- #pragma mark Table view methods
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- // Customize the number of rows in the table view.
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [[feed entries] count];
- }
- // Customize the appearance of table view cells.
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- }
- // Configure the cell.
- GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
- NSString *title = [[entry title] stringValue];
- NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];
- cell.textLabel.text = title;
- NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
- cell.imageView.image = [UIImage imageWithData:data];
- return cell;
- }
- - (void)dealloc {
- [super dealloc];
- }
- - (GDataServiceGoogleYouTube *)youTubeService {
- static GDataServiceGoogleYouTube* _service = nil;
- if (!_service) {
- _service = [[GDataServiceGoogleYouTube alloc] init];
- [_service setUserAgent:@"AppWhirl-UserApp-1.0"];
- [_service setShouldCacheDatedData:YES];
- [_service setServiceShouldFollowNextLinks:YES];
- }
- // fetch unauthenticated
- [_service setUserCredentialsWithUsername:nil
- password:nil];
- return _service;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement