Я создал свой собственный класс DialogViewController. Диалог имеет два уровня. Я хочу, чтобы пользователь мог нажать кнопку редактирования, чтобы он мог удалить элементы на втором уровне.CommitEditingStyle of Monotouch.Dialog RootElement
Позвольте мне попытаться объяснить, с какой-то код:
public class TestMenu : DialogViewController
{
public TestMenu() : base (new RootElement("Menu"), true)
{
Section section = new Section();
this.Root.Add (section);
RootElement firstRoot = new RootElement ("First level 1");
section.Add (firstRoot);
RootElement secondRoot = new RootElement ("First level 2");
section.Add (secondRoot);
// first rootelement
Section firstSection = new Section();
firstRoot.Add (firstSection);
StringElement firstElement = new StringElement ("Second level element 1");
firstSection.Add (firstElement);
// Button to set edit mode
Section buttonSection = new Section();
firstRoot.Add (buttonSection);
StringElement buttonElement = new StringElement ("Edit");
buttonElement.Tapped += delegate
{
// This works to get it in editing mode
firstRoot.TableView.SetEditing(true, true);
// This statement will not set it to editing mode
//this.SetEditing(true, true);
};
buttonSection.Add (buttonElement);
// second rootelement
Section secondSection = new Section();
secondRoot.Add (secondSection);
StringElement secondElement = new StringElement ("Second level element 2");
secondSection.Add (secondElement);
}
public override Source CreateSizingSource (bool unevenRows)
{
return new TestSource(this);
}
class TestSource : DialogViewController.SizingSource
{
public TestSource(DialogViewController container)
: base (container)
{}
public override bool CanEditRow (UITableView tableView, NSIndexPath indexPath)
{
return true;
}
public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
{
// This is only fired when something is deleted in the first level
base.CommitEditingStyle (tableView, editingStyle, indexPath);
}
}
}
Когда пользователь щелкает на ячейке редактирования таблицы находится в режиме редактирования.
Нажатие на значки удаления, конечно, ничего не делает. Как включить режим редактирования или прокрутку, чтобы показать кнопку удаления на корневых элементах второго уровня и далее?
Я прочитал следующий пост, который объясняет, как включить режим редактирования в диалоге контроллера вид первого экрана: http://monotouch.2284126.n4.nabble.com/Monotouch-Dialog-table-rows-not-selectable-in-edit-mode-td4658436.html
Это работает на первом уровне, но также возможно sublass источника в том же путь на втором уровне (элемент 1 второго уровня)?
Можете ли вы показать свой код для своего источника, где вы разрешаете редактирование? – therealjohn
Я обновил код, чтобы включить элемент Source. – Nessinot