Forum Xamarin Xamarin.iOS

Prevent rows from being editing using MonoTouch.Dialog

How do I intercept the call to bool CanEditRow (UITableView tableView, NSIndexPath indexPath) when using MonoTouch.Dialog?
I have elements that I don't want to make editable when the TableView enters editing mode. Overriding CanEditRow on my subclass of DialogViewController does not work as this method is not called, presumably because a DialogViewController uses its own TableSource.

I have looked for methods and properties on the elements that could be overridden or set to make them no editable(a natural place to do it I think) but I can't find anything. Thanks for your assistance!


  • SebastianSeidel.9226SebastianSeidel.9226 DEInsider, University ✭✭✭✭
    edited February 2014

    I solved this problem like this. At first I placed all elements I don't want to be editable in her own section. Then I implemented the source and override CanEditRow:

        public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
            if (Container.Root [0] == Container.Root [indexPath.Section])
                return false;
            return true;

    Update: My source is from type DialogViewController.Source, just to mention.

  • Thanks for your suggestion Sabastian. I have tried overriding CanEditRow in the dialogviewcontroller but it is not being called. I believe the reason it is not called is that dialogviewcontroller uses its own tablesource which prevents that from being called on the dialogviewcontroller. With this understanding I am at a loss to see how you were able to make it work.

  • How do you tell DialogViewController to use a subclass of source? If this were a normal table view I would just set it myself. But with the DialogViewController it is handling this all by itself I think. I figured this is where it is storing my elements.

  • Thanks for setting me on the right track Sabastian. There is a virtual method in DialogViewController that sets a UITableViewSource of subtype Source to the DialogViewController. This method is CreateSizingSource. By overriding this method it appears you can substitute you own subclass of Source which itself implements CanEditRow.

Sign In or Register to comment.