K.K.D
K.K.D

Reputation: 937

can't get contentOffset of tableView

I can't get scrolled tableView's position with this code.

CGPoint offset =  tableView.contentOffset;

I want to scroll tableView on before A ViewController position when I move A ViewController → B ViewController → A ViewController but it is always "(0,0)"....

UpDate------------ I could get contentOffset and implemented it

[self.tableView setContentOffset:ScrollOffset animated: YES];

But the cell's order has changed. For example, the cell's order is 1,2,3,4,5,6. If I select 4th cell,move to next ViewController and come back before ViewController, the cell's order has changed "4,5,6,1,2,3".... I don't want to change the order.just scroll tableView.

How can I solve it?

Upvotes: 0

Views: 1533

Answers (3)

Venomy
Venomy

Reputation: 2244

At which point do you try to get the contentOffset?

By using the following delegate function on UIScrollView you can get the contentOffset each time the view is scrolled.

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
        NSLog(@"%@", NSStringFromCGPoint(scrollView.contentOffset));

}

I hope this helps you find the cause of your problem

Upvotes: 1

Alisa_stranger
Alisa_stranger

Reputation: 81

Could you describe the question clearly ? We can easily get the contentOffset of tableView in scrollViewDidScroll delegate .

Upvotes: 0

Ronak Chaniyara
Ronak Chaniyara

Reputation: 5435

you can set content offset for UITableView like below, that will scroll your tableview:

CGPoint Offset = CGPointMake(0, 60);//pass your values here.

setContentOffset like below:

[tableView setContentOffset:Offset animated: YES];

OR

[tableView setContentOffset:CGPointMake(0, 60) animated: YES];

Upvotes: 0

Related Questions