2017-06-01 50 views
-2

我想知道我的滚动视图没有任何内容,那么我想把其他条件。 像如何知道我的滚动视图是空的

if (_scrollView == 0) 
    { 
     [self.addView setHidden:YES]; 
    } 
+1

您可以检查子视图计数。 'NSArray * arrSubviews = [myScrollView subviews];'如果数组数为0,那么scrollview没有内容。 – Mahesh

+0

我用如果(arrSubviews.count == 0)但这不起作用。 “如果不成立” –

回答

1

您可以检查子视图的计数。如果count大于0,那么您的滚动视图具有子视图。

UIScrollView *scrollview = [[UIScrollView alloc] init]; 

int currentCount = (int)scrollview.subviews.count; 

NSLog(@"Current Count: %d", currentCount); 
UILabel *lbl = [[UILabel alloc] init]; 
lbl.text = @"Temp"; 
[scrollview addSubview:lbl]; 

currentCount = (int)scrollview.subviews.count; 
NSLog(@"After Added Count: %d", currentCount); 
相关问题