7

我有一个应用程序,其中我有一个UITableView内部 a UIView,它又在内部 a UIScrollView,所以层次结构变成这样:

UIScrollView-> UIView->UITableView

my里面的数据UITableView是正确填写的。

现在,我的问题是,当我滚动我UITableViewUIScrollView's委托方法scrollViewDidEndDecelerating:并被scrollViewDidEndDragging::调用时。

我不想要这种行为,我应该怎么做才能阻止这种行为?

请哪位大神帮忙,先谢谢了!!!

4

2 回答 2

9

UITableViewDelegate extends UIScrollViewDelegate. Hence the calling of the delegate methods.

To stop this you can set tableView.tag = 1000; when you alloc the tableView and in the UIScrollViewDelegate methods ( scrollViewDidEndDecelerating: and scrollViewDidEndDragging:: )add this at the very begining:

if(scrollView.tag == 1000)
    return;
于 2012-07-10T10:19:03.527 回答
3

Because UITableView inherits from UIScrollView. So it shows all the properties and behaviours of UIScrollView. If you dont want this then please do one thing.

Assuming you have another scrollview in your page.

in the viewDidLoad or from the XIB (if you have your tableview in the XIB), set a tag for your tableview.

in code,

self.objYourTableView.tag = 101;

then in the scroll view delegate

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
  {
       if(!(scrollView.tag == 101))
       {
          // Go for your code to run.
       }
  }

So that your code will skip if it called by the table view. Other cases it works perfect. Hope this will help you.

于 2012-07-10T10:19:27.090 回答