MonoTouch How to implement RowSelected for UITableViewController with static cells

I am migrating my own objective-C application to the Monotouch solution.

I have a table view in my storyboard with some static table cells.

Using the following objective-C code a retrieved selection from a table

- (void) tableView:(UITableView *) aTableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath { // remove the row highlight [aTableView deselectRowAtIndexPath:indexPath animated:YES]; switch(indexPath.row) { case 0: [self callWebsite]; break; case 1: [self sendEmail]; break; case 2: [self makePhoneCall]; break; } return; } 

Now I want to do the same in MonoTouch, but I can’t find out how all the examples that I find on the network use DataSource and UITableViewDelegate.

But when using this approach, my "static" cells are deleted, replaced.

This is what I'm trying

 public partial class ContactViewController : UITableViewController { public ContactViewController (IntPtr handle) : base (handle) { this.TableView.Delegate = new CustomTableViewDelegate(); } } public class CustomTableViewDelegate : UITableViewDelegate { public override void RowSelected (UITableView tableView, NSIndexPath indexPath) { // Remove the row highlight RowDeselected(tableView, indexPath); /* // Is this section our "button" section? switch(indexPath.row) { case 0: [self callWebsite]; break; case 1: [self sendEmail]; break; case 2: [self makePhoneCall]; break; } */ Console.WriteLine("Do something meaningfull."); } } 

Anyone suggest?

+6
source share
1 answer

I think you should try using WeakDelegate to make this work.

In your controller, connect the method as follows:

 [Export("tableView:didSelectRowAtIndexPath:")] public void RowSelected (UITableView tableView, NSIndexPath indexPath) { //Your code here } 

Then set TableView.WeakDelegate = this;

Play with it, I may not have my exact parameters, etc.

+7
source

Source: https://habr.com/ru/post/913901/


All Articles