本文整理汇总了C#中UITableView.MoveRow方法的典型用法代码示例。如果您正苦于以下问题:C# UITableView.MoveRow方法的具体用法?C# UITableView.MoveRow怎么用?C# UITableView.MoveRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UITableView
的用法示例。
在下文中一共展示了UITableView.MoveRow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReactiveTableViewSource
public ReactiveTableViewSource(UITableView tableView, IEnumerable<TableSectionInformation> sectionInformation)
{
this.tableView = tableView;
this.sectionInformation = sectionInformation.ToList();
var compositeDisp = new CompositeDisposable();
this.innerDisp = compositeDisp;
for (int i=0; i < this.sectionInformation.Count; i++) {
var current = this.sectionInformation[i].Collection;
var section = i;
var disp = current.Changed.Buffer(TimeSpan.FromMilliseconds(250), RxApp.MainThreadScheduler).Subscribe(xs => {
if (xs.Count == 0) return;
this.Log().Info("Changed contents: [{0}]", String.Join(",", xs.Select(x => x.Action.ToString())));
if (xs.Any(x => x.Action == NotifyCollectionChangedAction.Reset)) {
this.Log().Info("About to call ReloadData");
tableView.ReloadData();
return;
}
int prevItem = -1;
var changedIndexes = xs.SelectMany(x => getChangedIndexes(x)).ToList();
changedIndexes.Sort();
for(int j=0; j < changedIndexes.Count; j++) {
// Detect if we're changing the same cell more than
// once - if so, issue a reset and be done
if (prevItem == changedIndexes[j] && j > 0) {
this.Log().Info("Detected a dupe in the changelist. Issuing Reset");
tableView.ReloadData();
return;
}
prevItem = changedIndexes[j];
}
this.Log().Info("Beginning update");
tableView.BeginUpdates();
var toChange = default(NSIndexPath[]);
foreach(var update in xs.Reverse()) {
switch(update.Action) {
case NotifyCollectionChangedAction.Add:
toChange = Enumerable.Range(update.NewStartingIndex, update.NewItems != null ? update.NewItems.Count : 1)
.Select(x => NSIndexPath.FromRowSection(x, section))
.ToArray();
this.Log().Info("Calling InsertRows: [{0}]", String.Join(",", toChange.Select(x => x.Section + "-" + x.Row)));
tableView.InsertRows(toChange, UITableViewRowAnimation.Automatic);
break;
case NotifyCollectionChangedAction.Remove:
toChange = Enumerable.Range(update.OldStartingIndex, update.OldItems != null ? update.OldItems.Count : 1)
.Select(x => NSIndexPath.FromRowSection(x, section))
.ToArray();
this.Log().Info("Calling DeleteRows: [{0}]", String.Join(",", toChange.Select(x => x.Section + "-" + x.Row)));
tableView.DeleteRows(toChange, UITableViewRowAnimation.Automatic);
break;
case NotifyCollectionChangedAction.Replace:
toChange = Enumerable.Range(update.NewStartingIndex, update.NewItems != null ? update.NewItems.Count : 1)
.Select(x => NSIndexPath.FromRowSection(x, section))
.ToArray();
this.Log().Info("Calling ReloadRows: [{0}]", String.Join(",", toChange.Select(x => x.Section + "-" + x.Row)));
tableView.ReloadRows(toChange, UITableViewRowAnimation.Automatic);
break;
case NotifyCollectionChangedAction.Move:
// NB: ReactiveList currently only supports single-item
// moves
this.Log().Info("Calling MoveRow: {0}-{1} => {0}{2}", section, update.OldStartingIndex, update.NewStartingIndex);
tableView.MoveRow(
NSIndexPath.FromRowSection(update.OldStartingIndex, section),
NSIndexPath.FromRowSection(update.NewStartingIndex, section));
break;
default:
this.Log().Info("Unknown Action: {0}", update.Action);
break;
}
}
this.Log().Info("Ending update");
tableView.EndUpdates();
});
compositeDisp.Add(disp);
}
}
示例2: MoveRow
public override void MoveRow(UITableView tableView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath)
{
int sourceRow = sourceIndexPath.Row;
int destRow = destinationIndexPath.Row;
float before, after;
Folder folder = controller.Folders[sourceRow];
// compute the new sort order for the folder based on the directiom of motion (up or down)
if (sourceRow < destRow)
{
// moving down - new position is the average of target position plus next position
before = controller.Folders[destRow].SortOrder;
if (destRow >= controller.Folders.Count - 1)
after = before + 1000f;
else
after = controller.Folders[destRow + 1].SortOrder;
}
else
{
// moving up - new position is the average of target position plus previous position
after = controller.Folders[destRow].SortOrder;
if (destRow == 0)
before = 0;
else
before = controller.Folders[destRow - 1].SortOrder;
}
float newSortOrder = (before + after) / 2;
// make a copy of the folder for the Update operation
Folder folderCopy = new Folder(folder);
folder.SortOrder = newSortOrder;
// enqueue the Web Request Record
RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
new RequestQueue.RequestRecord()
{
ReqType = RequestQueue.RequestRecord.RequestType.Update,
Body = new List<Folder>() { folderCopy, folder },
BodyTypeName = typeof(Folder).Name,
ID = folder.ID
});
// save the changes to local storage
StorageHelper.WriteFolder(folder);
StorageHelper.WriteFolders(App.ViewModel.Folders);
// re-sort the current folder list, and have the table view update its UI
controller.SortFolders();
tableView.MoveRow(sourceIndexPath,destinationIndexPath);
}
示例3: OnRecognizing
private static void OnRecognizing(LongPressGestureRecognizer recognizer, UITableView tableView, ViewCell cell)
{
NSIndexPath indexPath = tableView.IndexPathForRowAtPoint(recognizer.LocationInView(tableView));
switch (recognizer.State)
{
case UIGestureRecognizerState.Began:
if (indexPath != null)
{
// Remember the source row
recognizer.sourceIndexPath = indexPath;
recognizer.destinationIndexPath = indexPath;
cell.View.BackgroundColor = Color.Gray;
}
break;
case UIGestureRecognizerState.Changed:
if (recognizer.destinationIndexPath != null && indexPath != null && recognizer.destinationIndexPath != indexPath)
{
// Dragged to a new row location, so show it to the user with animation
tableView.MoveRow(recognizer.destinationIndexPath, indexPath);
recognizer.destinationIndexPath = indexPath;
}
break;
case UIGestureRecognizerState.Cancelled:
case UIGestureRecognizerState.Failed:
recognizer.sourceIndexPath = null;
cell.View.BackgroundColor = Color.Transparent;
break;
case UIGestureRecognizerState.Recognized:
// Move the data source finally
if (recognizer.sourceIndexPath != null && recognizer.destinationIndexPath != null && recognizer.sourceIndexPath != recognizer.destinationIndexPath)
{
// Reset the move because otherwise the underneath control will get out of sync with
// the Xamarin.Forms element. The next line will drive the real change from ItemsSource
tableView.MoveRow(recognizer.destinationIndexPath, recognizer.sourceIndexPath);
tableView.Source.MoveRow(tableView, recognizer.sourceIndexPath, recognizer.destinationIndexPath);
}
recognizer.sourceIndexPath = null;
recognizer.destinationIndexPath = null;
cell.View.BackgroundColor = Color.Transparent;
break;
}
}
示例4: MoveRow
public override void MoveRow(UITableView tableView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath)
{
if (sourceIndexPath.Section != 0 ||
destinationIndexPath.Section != 0)
return;
int sourceRow = sourceIndexPath.Row;
int destRow = destinationIndexPath.Row;
float before, after;
//Item item = controller.Sections[0].Items[sourceRow];
Item item = Sections[0].Items[sourceRow];
// compute the new sort order for the folder based on the directiom of motion (up or down)
if (sourceRow < destRow)
{
// moving down - new position is the average of target position plus next position
before = Sections[0].Items[destRow].SortOrder;
if (destRow >= Sections[0].Items.Count - 1)
after = before + 1000f;
else
after = Sections[0].Items[destRow + 1].SortOrder;
}
else
{
// moving up - new position is the average of target position plus previous position
after = Sections[0].Items[destRow].SortOrder;
if (destRow == 0)
before = 0;
else
before = Sections[0].Items[destRow - 1].SortOrder;
}
float newSortOrder = (before + after) / 2;
// make a copy of the item for the Update operation
Item itemCopy = new Item(item);
item.SortOrder = newSortOrder;
// enqueue the Web Request Record
RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
new RequestQueue.RequestRecord()
{
ReqType = RequestQueue.RequestRecord.RequestType.Update,
Body = new List<Item>() { itemCopy, item },
BodyTypeName = typeof(Item).Name,
ID = item.ID
});
// save the changes to local storage
StorageHelper.WriteFolder(Folder);
// re-sort the current list, and have the table view update its UI
SortList();
tableView.MoveRow(sourceIndexPath,destinationIndexPath);
}