示例#1
0
        void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (!loadedView)
            {
                return;
            }

            NSAction act = () => {
                if (e.Action == NotifyCollectionChangedAction.Reset)
                {
                    this.ReloadData();
                }

                if (e.Action == NotifyCollectionChangedAction.Add)
                {
                    var count = e.NewItems.Count;
                    var paths = new NSIndexPath[count];
                    for (var i = 0; i < count; i++)
                    {
                        paths [i] = NSIndexPath.FromRowSection(e.NewStartingIndex + i, 0);
                    }
                    this.InsertRows(paths, AddAnimation);
                    if (AutoScroll)
                    {
                        ScrollToRow(paths.Last(), UITableViewScrollPosition.None, true);
                    }
                }
                else if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    var count = e.OldItems.Count;
                    var paths = new NSIndexPath[count];
                    for (var i = 0; i < count; i++)
                    {
                        paths [i] = NSIndexPath.FromRowSection(e.OldStartingIndex + i, 0);
                    }
                    this.DeleteRows(paths, DeleteAnimation);
                }
            };

            var isMainThread = System.Threading.Thread.CurrentThread == mainThread;

            if (isMainThread)
            {
                act();
            }
            else
            {
                NSOperationQueue.MainQueue.AddOperation(act);
                NSOperationQueue.MainQueue.WaitUntilAllOperationsAreFinished();
            }
        }
示例#2
0
        void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (!loadedView)
                return;

            NSAction act = () => {

                if (e.Action == NotifyCollectionChangedAction.Reset) {
                    this.ReloadData ();
                }

                if (e.Action == NotifyCollectionChangedAction.Add) {
                    var count = e.NewItems.Count;
                    var paths = new NSIndexPath[count];
                    for (var i = 0; i < count; i++) {
                        paths [i] = NSIndexPath.FromRowSection (e.NewStartingIndex + i, 0);
                    }
                    this.InsertRows (paths, AddAnimation);
                    if(AutoScroll)
                        ScrollToRow(paths.Last(),UITableViewScrollPosition.None,true);
                } else if (e.Action == NotifyCollectionChangedAction.Remove) {
                    var count = e.OldItems.Count;
                    var paths = new NSIndexPath[count];
                    for (var i = 0; i < count; i++) {
                        paths [i] = NSIndexPath.FromRowSection (e.OldStartingIndex + i, 0);
                    }
                    this.DeleteRows (paths, DeleteAnimation);
                }
            };

            var isMainThread = System.Threading.Thread.CurrentThread == mainThread;

            if (isMainThread) {
                act ();
            } else {
                NSOperationQueue.MainQueue.AddOperation (act);
                NSOperationQueue.MainQueue.WaitUntilAllOperationsAreFinished ();
            }
        }