{"id":3353,"date":"2014-03-23T11:22:55","date_gmt":"2014-03-23T11:22:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/uipickerviews-subviews-count-is-always-3-in-ios-7-collection-of-common-programming-errors\/"},"modified":"2014-03-23T11:22:55","modified_gmt":"2014-03-23T11:22:55","slug":"uipickerviews-subviews-count-is-always-3-in-ios-7-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/uipickerviews-subviews-count-is-always-3-in-ios-7-collection-of-common-programming-errors\/","title":{"rendered":"UIPickerview&#39;s subviews count is always 3 in iOS 7?-Collection of common programming errors"},"content":{"rendered":"<p>I just started to migrate to iOS 7 and found several issues concerning UIPickerView in my app. And the reason is that I used the subviews of UIPickerView to customize it&#8217;s background and style. I am logging the subviews count of UIpickerview and it&#8217;s always is 3:<\/p>\n<pre><code>-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView\n {\n   return 1;\n }\n\n -(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent: (NSInteger)component\n{\n   return 22;\n}\n\n-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view\n{\n   UILabel* label = [[UILabel alloc]init];\n   label.frame = CGRectMake(152, 3,100, 16);\n   label.text = @\"test\";\n   NSLog(@\"count is %i\",_pickerView.subviews.count);\n   return label;\n}\n<\/code><\/pre>\n<p>I iOS 6.1, the count is always 9.<\/p>\n<p>Edit 1: Another difference: The bellow code crashes on iOS 7 and works without any problems on iOS 6.<\/p>\n<pre><code>-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view\n{ \n   UILabel* label = [[UILabel alloc]init];\n   label.frame = CGRectMake(152, 3,100, 16);\n   label.text = @\"test\";\n\n   if(row &gt; 3){\n     UIView* view = [pickerView viewForRow:3 forComponent:0]; \/\/ crash in iOS 7\n   }\n\n    NSLog(@\"count is %i\",_pickerView.subviews.count);\n    return label;\n}\n<\/code><\/pre>\n<p>Edit 2: _pickerView.showsSelectionIndicator = NO;<\/p>\n<p>has not any affection on iOS 7.<\/p>\n<p>Can someone explain how it works?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just started to migrate to iOS 7 and found several issues concerning UIPickerView in my app. And the reason is that I used the subviews of UIPickerView to customize it&#8217;s background and style. I am logging the subviews count of UIpickerview and it&#8217;s always is 3: -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { return 1; } -(NSInteger)pickerView:(UIPickerView *)thePickerView [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3353","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3353"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3353\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}