コード例 #1
0
		NSOperationQueue OperationQueueForCell (DataItemCollectionViewCell cell)
		{
			NSOperationQueue queue;
			if (operationQueues.TryGetValue (cell, out queue))
				return queue;

			queue = new NSOperationQueue ();
			operationQueues.Add (cell, queue);
			return queue;
		}
コード例 #2
0
        NSOperationQueue OperationQueueForCell(DataItemCollectionViewCell cell)
        {
            NSOperationQueue queue;

            if (operationQueues.TryGetValue(cell, out queue))
            {
                return(queue);
            }

            queue = new NSOperationQueue();
            operationQueues.Add(cell, queue);
            return(queue);
        }
コード例 #3
0
        public void ComposeCell(DataItemCollectionViewCell cell, DataItem dataItem)
        {
            var operationQueue = OperationQueueForCell(cell);

            operationQueue.CancelAllOperations();

            cell.RepresentedDataItem = dataItem;
            cell.Label.Text          = dataItem.Title;
            cell.ImageView.Alpha     = 1f;
            cell.ImageView.Image     = (UIImage)processedImageCache.ObjectForKey((NSString)dataItem.Identifier);

            if (cell.ImageView.Image != null)
            {
                return;
            }

            var processImageOperation = new NSBlockOperation();

            processImageOperation.AddExecutionBlock(() => {
                if (processImageOperation.IsCancelled)
                {
                    return;
                }

                UIImage image = null;
                DispatchQueue.MainQueue.DispatchSync(() => {
                    image = ProcessImageNamed(dataItem.ImageName);
                });

                if (image == null)
                {
                    return;
                }

                processedImageCache.SetObjectforKey(image, (NSString)dataItem.Identifier);
                NSOperationQueue.MainQueue.AddOperation(() => {
                    if (cell.RepresentedDataItem == null)
                    {
                        return;
                    }

                    cell.ImageView.Alpha = 0f;
                    cell.ImageView.Image = image;
                    UIView.Animate(0.25, () => cell.ImageView.Alpha = 1f);
                });
            });

            operationQueue.AddOperation(processImageOperation);
        }
コード例 #4
0
		public void ComposeCell (DataItemCollectionViewCell cell, DataItem dataItem)
		{
			var operationQueue = OperationQueueForCell (cell);
			operationQueue.CancelAllOperations ();

			cell.RepresentedDataItem = dataItem;
			cell.Label.Text = dataItem.Title;
			cell.ImageView.Alpha = 1f;
			cell.ImageView.Image = (UIImage)processedImageCache.ObjectForKey ((NSString)dataItem.Identifier);

			if (cell.ImageView.Image != null)
				return;

			var processImageOperation = new NSBlockOperation ();
			processImageOperation.AddExecutionBlock (() => {
				if (processImageOperation.IsCancelled)
					return;

				UIImage image = null;
				DispatchQueue.MainQueue.DispatchSync (() => {
					image = ProcessImageNamed (dataItem.ImageName);
				});

				if (image == null)
					return;

				processedImageCache.SetObjectforKey (image, (NSString)dataItem.Identifier);
				NSOperationQueue.MainQueue.AddOperation (() => {
					if (cell.RepresentedDataItem == null)
						return;

					cell.ImageView.Alpha = 0f;
					cell.ImageView.Image = image;
					UIView.Animate (0.25, () => cell.ImageView.Alpha = 1f);
				});
			});

			operationQueue.AddOperation (processImageOperation);
		}