views:

36

answers:

1

I have a DialogViewController with EnableSearch = true. Searching works fine and displays results in dialog. If I navigate into a result element or to another tab AND THEN come back to the search tab and try to tap any of the search result elements, I get "Argument is out of range.\nParameter name: index" at line 463 in DialogViewController.cs (var element = section.Elements [indexPath.Row];).

public class SearchView : DialogViewController
    {
        IFlickService _flickService;
        static IEnumerable<Flick> _flicks;

        public SearchView(IFlickService flickService) : base (UITableViewStyle.Grouped, null, true)
        {
            _flickService = flickService;
            _flicks = new List<Flick>();

            CreateUI();
        }

        public override void SearchButtonClicked (string text)
        {
            base.SearchButtonClicked (text);
            _flicks = _flickService.Search(text);
            CreateUI();         
        }

        void CreateUI()
        {
            EnableSearch = true;

            Root = new RootElement("Search For Flicks") {
                new Section(){
                    from f in _flicks
                    select (Element) new FlickElement(f, delegate { 
                        NavigationController.PushViewController(new FlickDetailView(_flickService, f), true);
                    })
                }
            };
        }   
    }
+1  A: 

The answer was to override ViewWillAppear() and move my call to CreateUI() from the constructor to ViewWillAppear(). I also had to move EnableSearch = true back into the constructor because it should be set before ViewWillAppear().

Byron Sommardahl