Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

UITableViewSource ReloadData causes RowSelected to fire

$
0
0

I'm trying to drill down through a UITableView using by changing the values for the TableView in a RowSelected event and then executing ReloadData to make it appear:

string[] newTableItems = new string[] {"Green Beans","Carrots","Celery"}; tableItems = newTableItems; tableView.ReloadData ();

The problem is that when the data is refreshed the first row in the TableView is automatically selected causing another RowSelected to fire and drill down to the first rows's destination.

Here's the complete UITableViewSourse implementation (hard coded for experimentation): public class TableSourceLeft : UITableViewSource { String[] tableItems; String cellIdentifier = "TableCell"; public UITableView theRightPane; String[] rightTableItems;

        public TableSourceLeft (string[] items, UITableView paRightPane)
        {
            tableItems = items;
            theRightPane = paRightPane;
        }
        public override int RowsInSection (UITableView tableview, int section)
        {
            return tableItems.Length;
        }
        public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
            // if there are no cells to reuse, create a new one
            if (cell == null) {
                if (leftPaneShowing == "I") {
                    cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellIdentifier);
                    cell.DetailTextLabel.Text = "Vendor";
                } else
                    cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
            }
            cell.TextLabel.Text = tableItems[indexPath.Row];
            return cell;
        }
        public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
        {
            //new UIAlertView("Row Selected", tableItems[indexPath.Row], null, "OK", null).Show();
            //tableView.DeselectRow (indexPath, true); // normal iOS behaviour is to remove the blue highlight
            if (leftPaneShowing == "C" && indexPath.Row == 0) {
                string[] newTableItems = new string[] {"Green Beans","Carrots","Celery"};
                tableItems = newTableItems;
                tableView.ReloadData ();
                leftPaneShowing = "S";
            }
            if (leftPaneShowing == "S" && indexPath.Row == 0) {
                if (ourData.phoneOrPad == UIUserInterfaceIdiom.Pad) {
                    string[] newTableItems = new string[] {"Item1","Item2","Item3","Item4","Item5"};
                    tableItems = newTableItems;
                    tableView.ReloadData ();
                    leftPaneShowing = "I";
                }               }
            if (leftPaneShowing == "I") {
                if (ourData.phoneOrPad == UIUserInterfaceIdiom.Pad) {
                    switch (indexPath.Row) {
                    case 0:
                        {
                            rightTableItems = new string[] {"Price:  12.00","Size: 12in","Weight: 14oz", "Color: Black", "Other", "Other", "other"};
                            break;
                        }
                    case 1:
                        {
                            rightTableItems = new string[] {"Price:  13.00","Size: 13in","Weight: 14oz", "Color: Black", "Other", "Other", "other"};
                            break;
                        }
                    case 2:
                        {
                            rightTableItems = new string[] {"Price:  14.00","Size: 14in","Weight: 14oz", "Color: Black", "Other", "Other", "other"};
                            break;
                        }
                    case 3:
                        {
                            rightTableItems = new string[] {"Price:  15.00","Size: 15in","Weight: 14oz", "Color: Black", "Other", "Other", "other"};
                            break;
                        }
                    default:
                        {
                            rightTableItems = new string[] {"Not found"};
                            break;
                        }
                    }
                    theRightPane.Source = new TableSourceRight(rightTableItems, null);
                    theRightPane.ReloadData ();
                }
            }
        }
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>