In my Xamarin iOS app I have the following code:
public class TableSource : UITableViewSource
{
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
new UIAlertView("Row Selected", TableItems[indexPath.Row], null, "OK").Show();
}
}
This successfully sends an alert whenever a new cell is selected by the user, however I want to be able to call this method, or a similar method, from within my ViewController. Basically so that I could click a button and it would return the currently selected cell.
I know that what I need is the TableItems[indexPath.Row] so is there anyway I could modify the RowSelected method further so that the value from TableItems[indexPath.Row] could be used again somewhere else?
I'm assuming that TableItems is an array that you have created. Create a variable to store the index. When the RowSelected method is called set the variable index to the value of the indexPath.Row. Whenever the method is called it will reset the value depending on which row was clicked and now you have the value and can use it elsewhere in your program
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With