Search code examples
uiscrollviewinstrumentsios-ui-automation

Retrieve number of views in a scrollview


I am currently trying to write some automated tests within instruments and am having a bit of an issue, is it possible to retrieve the number of views/panes in a scrollView so that I can say, if more than one view, scrollRight() for example?


Solution

  • int count = scrollview.subviews.count;
    
    if ( count > 1 ) 
    {
    .....
    }
    

    ??

    EDIT:

    You will need to get a reference to the view you are looking for. This will be done by iterating through your windows subview collection. In objective-C it would be something like this:

     NSInteger count = 0;
     for ( UIView *view in self.window.subviews )
     {
         if([view isKindOfClass:[UIScrollView class]])
         {
              count = (UIScrollView *) view.subviews.count;
         }
    
     }