How to animate tableView reload on UISegmentedControl click as pushviewcontroller

728 views Asked by At

I have relod the UITableview data on segment click as show in image below:

enter image description here

Now I want to animate tableView reload on UISegmentedControl click same as navigationController pushViewController but there appears transition screen between the movement of table view

I have try to use following but was unable to get totally what i wants to -(void)SwipeGestureRecognize{

    UISwipeGestureRecognizer * swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
    swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeleft];

    UISwipeGestureRecognizer * swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
    swiperight.direction=UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swiperight];



}
-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
{
    //past Order

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);

    }];

    self.tableView.frame = CGRectMake(0, 0, 0-[Util window_width], [Util window_height]);

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);
    }];



    segmetControl.selectedSegmentIndex = 1;
    [self action:Nil];

}

-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
{
    //Current Order

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);

    }];

    self.tableView.frame = CGRectMake(0, 0, 0-[Util window_width], [Util window_height]);

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);
     }];


    segmetControl.selectedSegmentIndex = 0;
    [self action:Nil];
}
2

There are 2 answers

7
Rajesh Maurya On

Please use below code.

-(void)swipeleft
{
        self.tableView.frame = CGRectMake(self.tableView.frame.size.width, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height)
        [UITableView animateWithDuration:0.5f animations:^{
            self.tableView.frame = CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);
        }];
}

 -(void)swiperight{
        self.tableView.frame = CGRectMake(-self.tableView.frame.size.width, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);

        [UITableView animateWithDuration:0.5f animations:^{
            self.tableView.frame = CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);

        }];
    }
4
Babul Prabhakar On

I would Suggest you to use a UICollectionView on the top and Make Custom Cells With view's width Containing UITableView and when the segment control valueChange: Scroll to particular Cell you want to use. Also Remember to Making

CollectionView PagingEnabled = YES