Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "HTTPService.h"
- #import "ViewController.h"
- #import "VideoCell.h"
- #import "Video.h"
- @interface ViewController ()
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (nonatomic,strong) NSArray *videoList;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
- self.videoList = [[NSArray alloc]init];
- [[HTTPService instance]getTutorials:^(NSArray * _Nullable
- dataArray, NSString * _Nullable errMessage)
- {
- if(dataArray){
- NSMutableArray *arr = [[NSMutableArray alloc]init];
- for (NSDictionary *d in dataArray){
- Video *vid = [[Video alloc]init];
- vid.videoTitle = [d objectForKey:@"title"];
- vid.videoDescription = [d objectForKey:@"description"];
- vid.thumbnailURL = [d objectForKey:@"thumbnail"];
- vid.videoIFrame = [d objectForKey:@"iframe"];
- [arr addObject:vid];
- }
- self.videoList = arr;
- [self updateTableData];
- }
- else if(errMessage)
- NSLog(@"Alert to user: %@",errMessage);
- }];
- }
- -(void) updateTableData{
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.tableView reloadData];
- });
- }
- - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView
- cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
- VideoCell *vCell = (VideoCell*)[tableView
- dequeueReusableCellWithIdentifier:@"main"];
- if(!vCell)
- vCell = [[VideoCell alloc]init];
- NSLog(@"here heree");
- return vCell;
- }
- - (NSInteger)tableView:(nonnull UITableView *)tableView
- numberOfRowsInSection:(NSInteger)section {
- NSLog(@"hererrrr");
- return self.videoList.count;
- }
- -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:
- (nonnull NSIndexPath *)indexPath{
- }
- -(void)tableView:(UITableView*)tableView willDisplayCell:(nonnull
- UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath
- *)indexPath{
- NSLog(@"Im in this bitch");
- Video *vid = [self.videoList objectAtIndex:indexPath.row];
- VideoCell *vidCell = (VideoCell*)cell;
- [vidCell updateUI:vid];
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement