ping
your Mac’s IP address from inside Windows, you should be good to go.UICollectionViewCell
, and create PhotoCollectionImageCell.cs
for you. Sweet, I wish Xcode did that! :]UICollectionViewDataSource
, which will provide data for the collection view. PhotoCollectionDataSource.cs
and add the following at the top of the file:UIKit
framework.UICollectionViewDataSource
class contains two abstract members you must implement. Add the following right inside the class:GetCell()
is responsible for providing a cell to be displayed within the collection view. DequeueReusableCell
reuses any cells that are no longer needed, for example if they’re offscreen, which you then simply return. If no reusable cell is available, a new one is created automatically.GetItemsCount
tells the collection view to display seven items.ViewController
class, which is the view controller that manages the scene containing the collection view. Switch back to Main.storyboard, select the collection view, then select the Widget tab. Enter collectionView for the Name.ViewController
class.collectionView
instance variable automatically generated by Visual Studio.ViewDidLoad()
, add these lines to instantiate the data source and connect it to the collection view.photoDataSource
will provide the data for the collection view.Photos
framework to access photo and video assets managed by the Photos app. cellImageView
for you.partial
, which indicates that the field is in another file.PhotoCollectionImageCell.cs
to expand the files. Open PhotoCollectionImageCell.designer.cs
to see cellImageView
declared there.PhotoCollectionImageCell.cs
and add the following method to the class:PhotoCollectionDataSource
to actually retrieve photos. PhotoCollectionDataSource
:imageFetchResult
field will hold an ordered list of photo entity objects, and you’ll get this photos list from the imageManager
.GetCell()
, add the following constructor:imageFetchResult
field. It then sets the imageManager
, which the app will query for more information about each image.imageManager
object when the class finishes by adding this destructor below the constructor.GetItemsCount
and GetCell
methods use these resources and return images instead of empty cells, change GetItemsCount()
to the following:GetCell
with the following:indexPath
contains a reference to which item in the collection view to return. The Item
property is a simple index. Here you get the asset at this index and cast it to a PHAsset
.imageManager
to request the image for the asset with a desired size and content mode.RequestImageForAsset
, and take a delegate to be called upon completion. When the request completes, the delegate will be called with the image and information about it.PhotoCollectionDataSource
class to inform it to re-query for photo changes. Add the following to the end of the class:ViewDidLoad()
:InvokeOnMainThread()
ensures that UI changes are always processed on the main thread; otherwise a crash may result.photoDataSource.ReloadPhotos()
to reload the photos and collectionView.ReloadData()
to tell the collection view to redraw.ViewDidLoad()
, add the following code right before setting photoDataSource
:NotDetermined
, explicitly requests permission to access photos.