Guest User

Untitled

a guest
Feb 16th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.01 KB | None | 0 0
  1. http://api.shoclef.com/api/NewsFeed?user_id=1164&pageno=1
  2.  
  3. -(void)newsFeedWithUserID:(int)userID PageNumber:(int)pageNumber CompletionBlock:(void(^)(BOOL error,NSArray * newsFeeds))completionBlock {
  4. NSString * url = [NSString stringWithFormat:@"%@NewsFeed?user_id=%i&pageno=%d",API_BASE_URL,userID,pageNumber];
  5. [self sendRequestWithJSONBody:nil urlEncoded:nil url:url method:@"GET" additionalHeaders:nil completionHandler:^(BOOL isError, NSDictionary *data) {
  6. if (!isError) {
  7. NSDictionary * temp = data[@"data"];
  8. NSMutableArray <NewsFeedDAO*>* feeds = [[NSMutableArray alloc]init];
  9. for (NSDictionary * feedDict in temp) {
  10. [feeds addObject:[NewsFeedDAO createFeedFromDict:feedDict]];
  11. completionBlock(NO,feeds);
  12. }
  13.  
  14. completionBlock(NO,feeds);
  15. }
  16. else {
  17. completionBlock(YES,nil);
  18. }
  19. }];
  20. }
  21.  
  22. -(void)getNewsfeedWithPageNumber:(int)pageNum {
  23. [SVProgressHUD showWithStatus:@"Loading..."];
  24. ApiManager * manager = [ApiManager sharedManager];
  25. UserDao * user = [[DatabaseManager sharedManager]getLoggedInUser];
  26.  
  27. [manager newsFeedWithUserID:user.userID PageNumber:pageNum CompletionBlock:^(BOOL error, NSArray *newsFeeds) {
  28. [SVProgressHUD dismiss];
  29. [[NSOperationQueue mainQueue]addOperationWithBlock:^{
  30. if (!error) {
  31. [self.arrNewsFeed addObjectsFromArray:newsFeeds];
  32. [self.tableView reloadData];
  33. pageNumber += 1;
  34.  
  35. }
  36. else {
  37. [EHPlainAlert showAlertWithTitle:@"Error" message:@"Newsfeed Shopper Not found" type:ViewAlertPanic];
  38. }
  39. }];
  40. }];
  41. }
  42.  
  43. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  44. NewsfeedShopperCell * cell= [tableView dequeueReusableCellWithIdentifier:@"newsfeedShopper" forIndexPath:indexPath];
  45. cell.title.text = [self.arrNewsFeed objectAtIndex:indexPath.row].title;
  46. cell.image.backgroundColor = [UIColor redColor];
  47.  
  48. //NSURL *imageUrl = [NSURL URLWithString:[self.images objectAtIndex:indexPath.row].image];
  49. NSString *strUrl = [self.arrNewsFeed objectAtIndex:indexPath.row].image;
  50. strUrl = [strUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
  51. [cell.image sd_setImageWithURL:[NSURL URLWithString:strUrl]];
  52.  
  53. cell.viewButton.tag = indexPath.row;
  54. self.pID = [self.arrNewsFeed objectAtIndex:indexPath.row].userID;
  55.  
  56. cell.actionViewButton = ^(UIButton * sender){
  57. NSInteger index = sender.tag;
  58. NSNumber * invoiceid = [NSNumber numberWithInteger:self.arrNewsFeed[index].userID];
  59. [self performSegueWithIdentifier:@"profile" sender:invoiceid];
  60. };
  61.  
  62. if (indexPath.row + 1 == self.arrNewsFeed.count) {
  63. [self getNewsfeedWithPageNumber:pageNumber];
  64. }
  65.  
  66. return cell;
  67. }
  68.  
  69. @interface BuyerSocialPage ()
  70. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  71. @property (weak, nonatomic) IBOutlet UIButton *sidebarButton;
  72. @property NSArray * profileImages;
  73. @property NSMutableArray * socialPageArray;
  74. @end
  75.  
  76. @implementation BuyerSocialPage
  77.  
  78. - (void)viewDidLoad {
  79. [super viewDidLoad];
  80. // Do any additional setup after loading the view.
  81. self.tableView.delegate=self;
  82. UINib * firstNib = [UINib nibWithNibName:@"BSPFirstCell" bundle:nil];
  83. [self.tableView registerNib:firstNib forCellReuseIdentifier:@"BSPFirstCell"];
  84. UINib * secondNib = [UINib nibWithNibName:@"BSPSecondCell" bundle:nil];
  85. [self.tableView registerNib:secondNib forCellReuseIdentifier:@"BSPSecondCell"];
  86. UINib * thirdNib = [UINib nibWithNibName:@"BSPThirdCell" bundle:nil];
  87. [self.tableView registerNib:thirdNib forCellReuseIdentifier:@"BSPThirdCell"];
  88. UINib * fourthNib = [UINib nibWithNibName:@"BSPFourthCell" bundle:nil];
  89. [self.tableView registerNib:fourthNib forCellReuseIdentifier:@"BSPFourthCell"];
  90. self.view.backgroundColor = [UIColor whiteColor];
  91. [self getBuyerSocialPage];
  92.  
  93. if (self.revealViewController) {
  94. [_sidebarButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
  95. [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
  96. }
  97.  
  98.  
  99. }
  100. -(void)getBuyerSocialPage {
  101. NSLog(@"getBuyerSocialPage");
  102. UserDao * profileID = [[DatabaseManager sharedManager]getLoggedInUser];
  103. ApiManager * manager = [ApiManager sharedManager];
  104. [manager socialPageWithProfileID:profileID.userID withCompletionBlock:^(BOOL error, NSDictionary *socialPage) {
  105. // NSMutableArray * details = [[NSMutableArray alloc]init];
  106. for (NSDictionary * temp in socialPage ) {
  107. [self.socialPageArray addObject:temp];
  108. }
  109. [self.tableView reloadData];
  110. if (!error) {
  111. self.profileImages=self.socialPageArray;
  112. }
  113. }];
  114. }
  115. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  116. return 1;
  117. }
  118. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  119. return 4;
  120. }
  121.  
  122. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  123. int row = (int)indexPath.row;
  124. if (row==0) {
  125. BSPFirstCell * firstcell = [tableView dequeueReusableCellWithIdentifier:@"BSPFirstCell"];
  126. firstcell.imageView.image = [UIImage imageNamed:@""];
  127.  
  128. // firstcell.imageView.image = [UIImage imageWithData: imageData];
  129.  
  130. return firstcell;
  131. }
  132. else if (row==1) {
  133. UITableViewCell * S_cell = [tableView dequeueReusableCellWithIdentifier:@"BSPSecondCell"];
  134. return S_cell;
  135. }
  136. else if (row==2) {
  137. UITableViewCell * T_cell = [tableView dequeueReusableCellWithIdentifier:@"BSPThirdCell"];
  138. return T_cell;
  139. }
  140. else {
  141. UITableViewCell *F_cell = [tableView dequeueReusableCellWithIdentifier:@"BSPFourthCell"];
  142. return F_cell;
  143. }
  144.  
  145. }
  146. - (void)scrollViewDidScroll: (UIScrollView *)scroll {
  147. // UITableView only moves in one direction, y axis
  148. CGFloat currentOffset = scroll.contentOffset.y;
  149. CGFloat maximumOffset = scroll.contentSize.height - scroll.frame.size.height;
  150.  
  151. // Change 10.0 to adjust the distance from bottom
  152. if (maximumOffset - currentOffset <= 10.0) {
  153. [self.tableView reloadData ];
  154. }
  155. }
  156. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  157. int row = (int)indexPath.row;
  158. if (row == 0) {
  159.  
  160. return 324;
  161. }
  162. else if (row == 1)
  163. {
  164. return 152;
  165. }
  166. else if (row == 2)
  167. {
  168. return 152;
  169. }
  170. else
  171. {
  172. return 152;
  173. }
  174.  
  175. }
  176.  
  177.  
  178. /*
  179. #pragma mark - Navigation
  180.  
  181. // In a storyboard-based application, you will often want to do a little preparation before navigation
  182. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  183. // Get the new view controller using [segue destinationViewController].
  184. // Pass the selected object to the new view controller.
  185. }
  186. */
  187.  
  188.  
  189. @end
  190.  
  191. enter user name=10016personal
  192. enter the password =1234@@
Add Comment
Please, Sign In to add comment