나는 내 자신의 DialogViewController 클래스를 만들었습니다. 대화 상자에는 두 가지 레벨이 있습니다. 사용자가 편집 버튼을 클릭하여 두 번째 레벨의 요소를 제거 할 수있게하려고합니다. Monotouch.Dialog RootElement의 CommitEditingStyle
나를 일부 코드를 설명하려고하자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
소스 요소를 포함하도록 코드를 업데이트했습니다. – Nessinot