Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://api.shoclef.com/api/NewsFeed?user_id=1164&pageno=1
- -(void)newsFeedWithUserID:(int)userID PageNumber:(int)pageNumber CompletionBlock:(void(^)(BOOL error,NSArray * newsFeeds))completionBlock {
- NSString * url = [NSString stringWithFormat:@"%@NewsFeed?user_id=%i&pageno=%d",API_BASE_URL,userID,pageNumber];
- [self sendRequestWithJSONBody:nil urlEncoded:nil url:url method:@"GET" additionalHeaders:nil completionHandler:^(BOOL isError, NSDictionary *data) {
- if (!isError) {
- NSDictionary * temp = data[@"data"];
- NSMutableArray <NewsFeedDAO*>* feeds = [[NSMutableArray alloc]init];
- for (NSDictionary * feedDict in temp) {
- [feeds addObject:[NewsFeedDAO createFeedFromDict:feedDict]];
- completionBlock(NO,feeds);
- }
- completionBlock(NO,feeds);
- }
- else {
- completionBlock(YES,nil);
- }
- }];
- }
- -(void)getNewsfeedWithPageNumber:(int)pageNum {
- [SVProgressHUD showWithStatus:@"Loading..."];
- ApiManager * manager = [ApiManager sharedManager];
- UserDao * user = [[DatabaseManager sharedManager]getLoggedInUser];
- [manager newsFeedWithUserID:user.userID PageNumber:pageNum CompletionBlock:^(BOOL error, NSArray *newsFeeds) {
- [SVProgressHUD dismiss];
- [[NSOperationQueue mainQueue]addOperationWithBlock:^{
- if (!error) {
- [self.arrNewsFeed addObjectsFromArray:newsFeeds];
- [self.tableView reloadData];
- pageNumber += 1;
- }
- else {
- [EHPlainAlert showAlertWithTitle:@"Error" message:@"Newsfeed Shopper Not found" type:ViewAlertPanic];
- }
- }];
- }];
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NewsfeedShopperCell * cell= [tableView dequeueReusableCellWithIdentifier:@"newsfeedShopper" forIndexPath:indexPath];
- cell.title.text = [self.arrNewsFeed objectAtIndex:indexPath.row].title;
- cell.image.backgroundColor = [UIColor redColor];
- //NSURL *imageUrl = [NSURL URLWithString:[self.images objectAtIndex:indexPath.row].image];
- NSString *strUrl = [self.arrNewsFeed objectAtIndex:indexPath.row].image;
- strUrl = [strUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
- [cell.image sd_setImageWithURL:[NSURL URLWithString:strUrl]];
- cell.viewButton.tag = indexPath.row;
- self.pID = [self.arrNewsFeed objectAtIndex:indexPath.row].userID;
- cell.actionViewButton = ^(UIButton * sender){
- NSInteger index = sender.tag;
- NSNumber * invoiceid = [NSNumber numberWithInteger:self.arrNewsFeed[index].userID];
- [self performSegueWithIdentifier:@"profile" sender:invoiceid];
- };
- if (indexPath.row + 1 == self.arrNewsFeed.count) {
- [self getNewsfeedWithPageNumber:pageNumber];
- }
- return cell;
- }
- @interface BuyerSocialPage ()
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (weak, nonatomic) IBOutlet UIButton *sidebarButton;
- @property NSArray * profileImages;
- @property NSMutableArray * socialPageArray;
- @end
- @implementation BuyerSocialPage
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.tableView.delegate=self;
- UINib * firstNib = [UINib nibWithNibName:@"BSPFirstCell" bundle:nil];
- [self.tableView registerNib:firstNib forCellReuseIdentifier:@"BSPFirstCell"];
- UINib * secondNib = [UINib nibWithNibName:@"BSPSecondCell" bundle:nil];
- [self.tableView registerNib:secondNib forCellReuseIdentifier:@"BSPSecondCell"];
- UINib * thirdNib = [UINib nibWithNibName:@"BSPThirdCell" bundle:nil];
- [self.tableView registerNib:thirdNib forCellReuseIdentifier:@"BSPThirdCell"];
- UINib * fourthNib = [UINib nibWithNibName:@"BSPFourthCell" bundle:nil];
- [self.tableView registerNib:fourthNib forCellReuseIdentifier:@"BSPFourthCell"];
- self.view.backgroundColor = [UIColor whiteColor];
- [self getBuyerSocialPage];
- if (self.revealViewController) {
- [_sidebarButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
- }
- }
- -(void)getBuyerSocialPage {
- NSLog(@"getBuyerSocialPage");
- UserDao * profileID = [[DatabaseManager sharedManager]getLoggedInUser];
- ApiManager * manager = [ApiManager sharedManager];
- [manager socialPageWithProfileID:profileID.userID withCompletionBlock:^(BOOL error, NSDictionary *socialPage) {
- // NSMutableArray * details = [[NSMutableArray alloc]init];
- for (NSDictionary * temp in socialPage ) {
- [self.socialPageArray addObject:temp];
- }
- [self.tableView reloadData];
- if (!error) {
- self.profileImages=self.socialPageArray;
- }
- }];
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 4;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- int row = (int)indexPath.row;
- if (row==0) {
- BSPFirstCell * firstcell = [tableView dequeueReusableCellWithIdentifier:@"BSPFirstCell"];
- firstcell.imageView.image = [UIImage imageNamed:@""];
- // firstcell.imageView.image = [UIImage imageWithData: imageData];
- return firstcell;
- }
- else if (row==1) {
- UITableViewCell * S_cell = [tableView dequeueReusableCellWithIdentifier:@"BSPSecondCell"];
- return S_cell;
- }
- else if (row==2) {
- UITableViewCell * T_cell = [tableView dequeueReusableCellWithIdentifier:@"BSPThirdCell"];
- return T_cell;
- }
- else {
- UITableViewCell *F_cell = [tableView dequeueReusableCellWithIdentifier:@"BSPFourthCell"];
- return F_cell;
- }
- }
- - (void)scrollViewDidScroll: (UIScrollView *)scroll {
- // UITableView only moves in one direction, y axis
- CGFloat currentOffset = scroll.contentOffset.y;
- CGFloat maximumOffset = scroll.contentSize.height - scroll.frame.size.height;
- // Change 10.0 to adjust the distance from bottom
- if (maximumOffset - currentOffset <= 10.0) {
- [self.tableView reloadData ];
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- int row = (int)indexPath.row;
- if (row == 0) {
- return 324;
- }
- else if (row == 1)
- {
- return 152;
- }
- else if (row == 2)
- {
- return 152;
- }
- else
- {
- return 152;
- }
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
- enter user name=10016personal
- enter the password =1234@@
Add Comment
Please, Sign In to add comment