6

I have category for UIScrollView for customization

I need get UIScrollView.

I try

UIScrollView *scroll = nil;
for (UIView* subview in self.tableView.subviews) {
    NSLog(@"%i", self.tableView.subviews.count);

    if ([subview isKindOfClass:[UIScrollView class]]) {
        scroll = (UIScrollView *)subview;
        //some code
    }
}

But it doesn't work. How I can get ScrollView? Thanks

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Alexander
  • 627
  • 2
  • 11
  • 23
  • this is very nice explanation take a look:-http://stackoverflow.com/questions/1703023/is-it-possible-to-access-a-uitableviews-scrollview-in-code-from-a-nib – Nitin Gohel Aug 31 '13 at 07:34

2 Answers2

23

UITableView is a subclass of UIScrollView, not a subview (or vice-versa as your code tries), so you should just use the table view directly.

Wain
  • 118,658
  • 15
  • 128
  • 151
1

UIScrollView is not subview but UIScrollView is superclass of UITableView you can call method or get variable of UIScrollView by through UIScrollView, If you want to get UIScrollView you can use by this

var scroll = self.tableView as UIScrollView
//some code

Or you want to compare you can use

if scrollView == self.tableView {
    //some code 
}
  • thanks it works , I required it to pass UIScrollView as a variable in a method to check scrollview content offset position. – KrishnDip Oct 19 '22 at 10:55