Sorry, I totally forgot: the default behaviour for a MT.D Search thing is to filter the items which are in the current list! So, if you add 10 items, it will then look at each, find something which matches, and show that.
So you may need to dig around under the hood, and see how the search works, and reproduce it yourself. eg, you might need to make a new SearchDelegate, and replicate what SetupSearch does to recreate the UISearchBar + delegate. Being a lot of this isn't virtual (I tend to fork MT.D and add a LOT of virtuals in!), it might be easier to subclass DialogViewController, and just do the search bits yourself. On Fri, Jun 29, 2012 at 9:44 AM, Kim Bjørn Tiedemann <[email protected]> wrote: > Hi Nic, > > Thanks a lot for your reply. > > I am still having issues and the following VERY simple example does not > reload the data in the table: > > public partial class SearchViewController : DialogViewController > { > > public SearchViewController () : base (UITableViewStyle.Plain, null) > { > > Root = new RootElement("Results") { > new Section("No results") > } ; > > EnableSearch = true; > > SearchTextChanged += delegate(object sender, SearchChangedEventArgs args) { > Root = GetResults(); > } ; > > } > > private RootElement GetResults () > { > return new RootElement("Results") { > new Section("Sec1") { > new StyledStringElement("Testing1", "test1"), > new StyledStringElement("Testing2", "test2") > } > } ; > > } > } > > I have tried debugging and the changes to the Root property seems to > "remove" the section object inside the RootElement. So that the first time I > enter the SearchTextChanged and set the Root is has the correct number of > sections. The second time is has no sections. > > Do you know what the problem is? > > Thanks in advance > > Kim > > On Thu, Jun 28, 2012 at 9:40 AM, Nic Wise <[email protected]> wrote: >> >> Hi Kim >> >> SearchTextChanged it called as you type, so it should go each time you >> hit a key. >> >> To get rid of the keyboard, you need to use the ResignFirstResponder >> method, or you can try setting EndEditing to true (you need to either >> call it on the searchbox, or on the dialogviewcontroller itself) >> >> As for the rest of it (pun kind of intended), I would: >> >> 1. get the SearchTextChanged event, and start a timer. if the timer >> fires, keep going. If the user hits another key, restart the timer. >> 2. when the timer fires, start a new thread (ThreadPool, or use >> System.Threading.Tasks) and do your rest call. >> 3. Once you have the data, use InvokeOnMainThread (which is on any UI* >> object, or even NSString or NSObject) to pass in the results of the >> search, and update the dialogviewcontroller. You MUST do the update on >> the UI thread, and unless you want the UI to jump and around and stop >> and stutter, you need to do the rest call (and any other non-UI >> processing) OFF the main thread. >> >> How you do the update is up to you. For a first attempt, just rebuild >> the Root and reload it. If thats not smooth enough, you may need to >> take the current root, insert the new results in the right places, and >> allow it to animate the table cells (you get the animations for free, >> pretty much) >> >> //in a thread, do the rest calls >> >> ThreadPool.QueueUserWorkItem(delegate { >> >> var results = DoSomeWorkAndGetSomeResults(searchText); >> >> //once you have the results, update the UI - check to see if the >> object you are using has InvokeOnMainThread, if so, you dont need to >> make a string to use it :) >> >> var temp = new NSString("foo"); >> >> temp.InvokeOnMainThread(delegate { >> var localresults = results; //keep a reference to it >> >> var newroot = new RootElement("results!"); >> //add in secetions and elements based on your rest results >> foreach(var result in localresults) { >> //do stuff, make objects, put them into the root >> } >> >> Root = newroot; //display it. >> >> }); >> >> }); >> >> >> >> >> >> On Wed, Jun 27, 2012 at 1:50 PM, tiede <[email protected]> wrote: >> > I am new to mono touch and iOs programming. >> > >> > I am considering using the mono touch dialog for showing a search result >> > from a REST service. So the table is initially empty but by pressing the >> > search button (search is enabled in the dialog viewcontroller). >> > >> > Is this an ok use of the dialogviewcontroller? And what it the right >> > pattern >> > for calling the service and supplying the result into the "model" of the >> > controller? >> > >> > I have tried implementing in the SearchButtonClicked and that works but >> > the >> > keyboard does not disappear. I have tried in the SearchTextChanged but >> > the >> > data is not refreshed. >> > >> > So I am looking for a pattern for this kind of use case? >> > >> > Thanks in advance >> > >> > Kim >> > >> > -- >> > View this message in context: >> > http://monotouch.2284126.n4.nabble.com/DialogViewController-and-async-search-tp4655604.html >> > Sent from the MonoTouch mailing list archive at Nabble.com. >> > _______________________________________________ >> > MonoTouch mailing list >> > [email protected] >> > http://lists.ximian.com/mailman/listinfo/monotouch >> >> >> >> -- >> Nic Wise >> t. +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise >> b. http://www.fastchicken.co.nz/ >> >> Earnest: Self-employed? Track your business expenses and income. >> http://earnestapp.com >> Nearest Bus: find when the next bus is coming to your stop. >> http://goo.gl/Vcz1p >> mobileAgent (for FreeAgent): get your accounts in your pocket. >> http://goo.gl/IuBU >> Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa >> London Bike App: Find the nearest Boris Bike, and get riding! >> http://goo.gl/Icp2 > > -- Nic Wise t. +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise b. http://www.fastchicken.co.nz/ Earnest: Self-employed? Track your business expenses and income. http://earnestapp.com Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p mobileAgent (for FreeAgent): get your accounts in your pocket. http://goo.gl/IuBU Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2 _______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
