コード例 #1
0
            void UpdateStructure(IReadOnlyList <Item> newList)
            {
                var edits = ListEdit.GetListEdits(items, newList);

                items = newList;

                var        columns       = tableView.TableColumns();
                NSIndexSet allColumnsSet = null;

                foreach (var e in edits)
                {
                    switch (e.Type)
                    {
                    case ListEdit.EditType.Insert:
                        using (var set = new NSIndexSet(e.Index))
                            tableView.InsertRows(set, NSTableViewAnimation.None);
                        break;

                    case ListEdit.EditType.Delete:
                        using (var set = new NSIndexSet(e.Index))
                            tableView.RemoveRows(set, NSTableViewAnimation.None);
                        break;

                    case ListEdit.EditType.Reuse:
                        if (owner.OnUpdateView != null && owner.OnCreateView != null)
                        {
                            for (int col = 0; col < columns.Length; ++col)
                            {
                                var existingView = tableView.GetView(col, e.Index, makeIfNecessary: false);
                                if (existingView != null)
                                {
                                    owner.OnUpdateView((Item)e.Item, columns[col], existingView, (Item)e.OldItem);
                                }
                            }
                        }
                        else
                        {
                            if (allColumnsSet == null)
                            {
                                allColumnsSet = NSIndexSet.FromArray(Enumerable.Range(0, columns.Length).ToArray());
                            }
                            using (var set = new NSIndexSet(e.Index))
                                tableView.ReloadData(set, allColumnsSet);
                        }
                        break;
                    }
                }

                allColumnsSet?.Dispose();
            }