Continuing from the previous post that used a UICollectionView to display a grid of images from Bing, the following example adds a UICollectionView to a UISplitViewController.
When the row is selected, a new search is issued and the resulting images are updated in the UICollectionView. To connect the selection in the UISplitViewController’s master controller, which is an MT.D DialogViewController in this case, to the UICollectionViewController contained in the UISplitViewController’s detail controller, an event is raised when a row is selected:
public AnimalsController () : base (null) { Root = new RootElement ("Animals") { new Section () { from animal in animals select (Element) new StringElement(animal, () => { if(AnimalSelected != null) AnimalSelected(this, new AnimalSelectedEventArgs{Animal = animal}); }) }}; }
Then the UISplitViewController’s implementation handles this event to communicate to the UICollectionViewController:
animalImageController = new BingImageGridViewController (layout); animalsController.AnimalSelected += (sender, e) => { animalImageController.LoadImages (e.Animal); };
In the LoadImages method, the UICollectionViewController calls Bing for the selected item and uploads the UICollectionView when the data is returned by calling ReloadData:
public void LoadImages (string search) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; bing = new Bing ((results) => { InvokeOnMainThread (delegate { imageUrls = results; CollectionView.ReloadData (); UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; }); }); bing.ImageSearch (search); }
The sample is available at https://github.com/mikebluestein/BingImageGrid/tree/master/BingImageGridSplit
Note: you’ll need a Bing API key, which you can get at http://datamarket.azure.com
Hi Mike, I was checking this article to give me an idea on how to consume remote images and display them on CollectionView, but I’m facing a problem with how they render.
I’m consuming imgur’s API instead of Bing in my case, so I needed to implement my own method to get the urls and then downloaded each image into a UIImage that would be stored in a List, these List is assigned to my CollectionViewSource’s photos list, after that I call ReloadData on my collection view, but the cells aren’t rendered right, some images are displayed and some not, if I scroll some of the ones that were shown disappear and some of the ones that didn’t show are displayed.
I get this flashing effect on my cells but I have no idea why is it happening. I placed the code for my image API consumption here http://pastebin.com/D1Qka9gP.
Do you have an idea on why I get this problem?