1

There is only one UITableView in my view controller and there's my code:

@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.scrollsToTop = YES;
[self.view addSubview:self.tableView];

It even does not run the :

- (BOOL) scrollViewShouldScrollToTop:(UIScrollView*) scrollView

I dont know why, how can I fix this? Thank you very much.

jxdwinter
  • 2,339
  • 6
  • 36
  • 56
  • Are there any other scroll views (or scroll view subclasses, such as table view or collection view) on the screen? – Toseef Khilji Oct 15 '13 at 06:14
  • @Virussmca Thank you for your reply and I'm using some 3rd part library, there's another uitableView behind my TableView. – jxdwinter Oct 15 '13 at 06:23
  • 1
    As apple's docs say, "On iPhone, the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to YES." – Toseef Khilji Oct 15 '13 at 06:26
  • 1
    @Virussmca OK, I see that! Please leave an answer,I will vote it. – jxdwinter Oct 15 '13 at 06:29

3 Answers3

7

Do you have more than one scrollview or tableview or collectionview on screen?

If so, only one of them can have scrollsToTop set to YES, otherwise iOS7 will not scroll any of them to the top.

As apple's docs say, "On iPhone, the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to YES."

Reference from Can't get scrollsToTop working on iOS7

Community
  • 1
  • 1
Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
0

ScrollsToTop is not a method of UITableViewDelegate/UITableViewDatasource. Try to add the UIScrollDelegate in to MyViewController interface.

Javi Campaña
  • 1,481
  • 1
  • 22
  • 30
0

You may forget to take ScrollView Delegate.

@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>

instead of 

@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>
user1673099
  • 3,293
  • 7
  • 26
  • 57