Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #import "HTTPService.h"
  2. #import "ViewController.h"
  3. #import "VideoCell.h"
  4. #import "Video.h"
  5.  
  6. @interface ViewController ()
  7. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  8. @property (nonatomic,strong) NSArray *videoList;
  9. @end
  10.  
  11. @implementation ViewController
  12.  
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15.  
  16. self.tableView.dataSource = self;
  17. self.tableView.delegate = self;
  18.  
  19. self.videoList = [[NSArray alloc]init];
  20.  
  21. [[HTTPService instance]getTutorials:^(NSArray * _Nullable
  22. dataArray, NSString * _Nullable errMessage)
  23. {
  24. if(dataArray){
  25. NSMutableArray *arr = [[NSMutableArray alloc]init];
  26.  
  27. for (NSDictionary *d in dataArray){
  28. Video *vid = [[Video alloc]init];
  29. vid.videoTitle = [d objectForKey:@"title"];
  30. vid.videoDescription = [d objectForKey:@"description"];
  31. vid.thumbnailURL = [d objectForKey:@"thumbnail"];
  32. vid.videoIFrame = [d objectForKey:@"iframe"];
  33.  
  34. [arr addObject:vid];
  35. }
  36.  
  37. self.videoList = arr;
  38. [self updateTableData];
  39.  
  40. }
  41. else if(errMessage)
  42. NSLog(@"Alert to user: %@",errMessage);
  43. }];
  44.  
  45.  
  46. }
  47.  
  48. -(void) updateTableData{
  49. dispatch_async(dispatch_get_main_queue(), ^{
  50. [self.tableView reloadData];
  51. });
  52. }
  53.  
  54. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView
  55. cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  56.  
  57. VideoCell *vCell = (VideoCell*)[tableView
  58. dequeueReusableCellWithIdentifier:@"main"];
  59.  
  60. if(!vCell)
  61. vCell = [[VideoCell alloc]init];
  62. NSLog(@"here heree");
  63. return vCell;
  64. }
  65.  
  66. - (NSInteger)tableView:(nonnull UITableView *)tableView
  67. numberOfRowsInSection:(NSInteger)section {
  68. NSLog(@"hererrrr");
  69. return self.videoList.count;
  70. }
  71.  
  72. -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:
  73. (nonnull NSIndexPath *)indexPath{
  74.  
  75. }
  76.  
  77. -(void)tableView:(UITableView*)tableView willDisplayCell:(nonnull
  78. UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath
  79. *)indexPath{
  80. NSLog(@"Im in this bitch");
  81. Video *vid = [self.videoList objectAtIndex:indexPath.row];
  82. VideoCell *vidCell = (VideoCell*)cell;
  83. [vidCell updateUI:vid];
  84. }
  85.  
  86. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  87. return 1;
  88. }
  89.  
  90. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement