ios - Is UICollectionView.backgroundView broken -


i'm writing relatively simple, or thought.

firstly, code, i'm trying place image on background of uicollectionview if there no results returned server. image 200 200:

uiview *myview = [[uiview alloc] initwithframe:self.view.bounds]; cgrect myviewspace = self.view.bounds; cgfloat myx = (myviewspace.size.width /2.0) - 100; cgfloat myy = (myviewspace.size.height /2.0) - 100; uiimageview *imview = [[uiimageview alloc] initwithframe:cgrectmake(myx, myy, 200, 200)]; imview.image = [uiimage imagenamed:@"imnothome"]; [myview addsubview:imview]; mycollectionview.backgroundview = myview; 

once there results, want able remove it.

i thought it'd simple placing following, before reloaded uicollectionview:

[mycollectionview.backgroundview removefromsuperview]; 

however, appears doing nothing.

am missing something?

thanks in advance!

it should done way instead:

mycollectionview.backgroundview = nil; 

explanation: should unset uicollectionview's background in same way set it. didn't set manipulating view hierarchy, setting background property. did call addsubview in previous line, add subview background view, not add background view itself.

edit:

there article uicollectionview bug here: http://blog.spacemanlabs.com/2013/11/uicollectionviews-backgroundview-property-is-horribly-broken/

the solution author gives reset background empty opaque view:

uiview *blankview = [uiview new]; blankview.backgroundcolor = [uicolor whitecolor]; [mycollectionview.backgroundview removefromsuperview]; mycollectionview.backgroundview = blankview; 

also, author recommends not using backgroundview property @ doing yourself:

frankly, think best solution ignore backgroundview property together. instead, make collection view’s background clear, , implement own backgroundview; throw view behind collection view.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -