Xamarin.iOSのテーブルビューにスワイプノーマル(右から左を意味します)という2つのアクションが必要です。セル/ Xamarin.iOSを削除するためのUITableViewDelegateでNSInternalInconsistencyExceptionエラーが発生しました
私が検索したとき、私は自分のテーブルのUITableViewDelegateをカスタマイズして、さまざまな操作でスワイプを作成できることを知っています。 、私は、二つの作用を持っている "活性化" と "削除" があり
public class NotificationTableDelegate : UITableViewDelegate
{
private readonly AlertsViewController _AlertsViewController;
private List<NotificationItem> _notifications;
public NotificationTableDelegate(AlertsViewController tagViewController, List<NotificationItem> notifs)
{
_AlertsViewController = tagViewController;
_notifications = notifs;
}
public override UITableViewRowAction[] EditActionsForRow(UITableView tableView, NSIndexPath indexPath)
{
UITableViewRowAction activateOrDeactivateNotifAction = UITableViewRowAction.Create(
UITableViewRowActionStyle.Normal,
"activate",
delegate {
//activate or deactivate
}
);
UITableViewRowAction deleteNotifAction = UITableViewRowAction.Create(UITableViewRowActionStyle.Destructive,"Delete",async delegate
{
UIAlertController alert = UIAlertController.Create(_notifications.ElementAt(indexPath.Row).Label, "ConfirmDeleteAlert", UIAlertControllerStyle.Alert);
alert.AddAction(UIAlertAction.Create("Yes", UIAlertActionStyle.Destructive, (action) => {
_notifications.RemoveAt(indexPath.Row);
tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
}));
alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (action) => { }));
await _AlertsViewController.PresentViewControllerAsync(alert, true);
});
return new UITableViewRowAction[] { deleteNotifAction, activateOrDeactivateNotifAction };
}
}
:
は、ここに私のUITableViewDelegateコードです。ここまでは、すべてうまく動作しますが、削除のためのアクションは私にエラーです。 私は行を削除し、削除を受け入れた後にするとき、それは私NSInternalInconsistencyExceptionエラーになり:
Objective-Cの例外がスローされました。名前:NSInternalInconsistencyException 理由:無効な更新:セクション0の行数が無効です。更新後の既存のセクション( )に含まれる行の数が、そのセクションに含まれる行の数と等しくなければなりません。 更新(0が挿入され、1が削除された) の行がそのセクションの内外に移動された(0が移動され、0が移動された)から挿入または削除された行の数をプラスまたはマイナスします。 。
テーブルのセル数が変わる必要があるため、NotificationTableDelegateではUITableViewSourceの項目にアクセスできないため、エラーは正しいと思います!!このエラーを解決するにはどうすればよいですか、またはUITableViewSourceのアイテムを変更するにはどうすればよいですか?何か案が?
* CommitEditingStyleなどを使用してUITableViewSource内での削除を行うためのコードがありますが、それは私の場合ではありません。 さらに、私はCanEditRowを持っています、UITableViewSourceで真です。
あなたは正しいですよ。ColeXia – ali