Alexander
Alexander

Reputation: 637

UITableView get UIScrollView for customization

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

Upvotes: 7

Views: 11390

Answers (2)

Saharat Sittipanya
Saharat Sittipanya

Reputation: 321

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 
}

Upvotes: 1

Wain
Wain

Reputation: 119031

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.

Upvotes: 23

Related Questions