I've looked at other UITableView questions, but did not find any that matches this scenario.
I have a normal UITableViewController that accepts an array from a search form (IOW, dynamic data). The form has a push segue to the table VC, and the table cells have another push segue to a 'details' type of screen for each item. In the table view, I call reloadData in viewDidAppear.
The first time I test the search, the table displays the "no results" view (in a screen-wide cell) that I programmed into it, but only for about 1 second. After that, the search results appear as expected and the navigation works fine.
How can I get rid of this initial glitch?
EDIT: (#Paulw11's request) The search operation is network-based, and I call performSegueWithIdentifier in the dispatch_get_main_queue block. The data is passed in prepareForSegue as an NSArray (with multiple items per index).
This was actually an issue with the segue from the search controller to the table firing twice.
In my case, this was caused by the segue being wired to the search button instead of to the search view controller itself.
Related
I'm building my first app using Swift and have done a few modules from the CodeWithChris website. I'm just doing this as a hobby.
The main ViewController has a tableView with a list of records that are retrieved from FireStore. If you click one of the records, it will open another ViewController through a prepare for segue function and brings up a detail screen with various fields from that record for editing.
So back to the main view: In the tableView prototype cell, I have a horizontal stack view in which has two of the fields from the record and then I've added a button which I'd like to open a separate View different from the first I've described above but similar - so that it will bring up a detailed record view but with an entirely different set of fields that the other.
The concept is I'm tracking animal health histories so it shows a list of the animal names and types and when you click on the name or type, it goes to that first view with details about that animal. Then from that main tableview, I have a button that I want to bring up the vaccination history. I tried to do a prepare for segue by dragging the button to a new view controller but that didn't seem to work.
I'm just looking for the general idea of what I have to do and can probably use that feedback to maybe figure it out.
I figured it out. The segue identifier lets me set up some conditions within the prepare for segue function to active my goal!
I have looked all over for this problem and I cannot find an answer.
So on the first page of my app I have a page in a navigation controller. Within that page is a tableview. Within the cells of the table, there is a button. For the view controller of the cells, I say remove the button from superview if user is not signed in. So when you first load the app, there is no button.
Now if you click the sign in button (a button at the top of the page), it goes to that page, then there's two possible things that can happen. At first what I was doing was making a segue back to the main page. Everything worked perfectly fine. The button appears in the cells.
But I don't like how a second copy of the main page is being added to the stack of navigation controllers. So what I have explored with now is the popnavigationcontroller method and the unwind segue. So they both work but the problem is when it unwinds back to the new page, the button I mentioned earlier does not appear in the cells, even though its supposed to appear since the user is signed in. The reason for this is because the method "dequeueReusuableCell" is using the old cells, in which I have removed the button. And now that the button is removed, there is no easy way for me to add it back in at the right place in the view.
So what is the best solution here? At first I was looking for a way to "clear" all the reusuablecells for a tableView but I'm not sure if I found an answer. What I would like to do is when I rewind back to that navigation controller, refresh everything like it was the first time ever seeing it.
I guess another solution I could do is to perform a normal segue from the sign in page to the main page, and then remove the previous redundant main navigation controller. Is there a better solution?
When your controller pops off the stack, the underlying view controller will have its viewDidAppear(animated:) function called. So you could have:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
tableView.reloadData()
}
This is assuming based on your post that the issue is only about reloading your table. If you reload the table and your cells are still not updating properly, you have an issue with your dataSource not configuring the cells properly. But I cannot tell if this is the case without any code.
Edit: this was a cell reuse issue. Cell configuation had some code to remove a subview in some instances, but never add the subview back if it was supposed to be there. The simplest fix is to use isHidden instead of outright removing the subview.
I'm not sure if I explained this correctly in my question, so I'll explain it here. Please excuse my iOS illiteracy, complete newbie here.
The master view controller is a UITableViewController that holds a list of items. So, each cell contains an item. This list is populated from a Core Data model.
If I want to add an item, there's an Add button that takes me to a different view controller that has a text field. I write the item name in the text field, press the Done button and it adds it to Core Data, and unwinds back to the UITableViewController.
I want the table view to reload its data as soon as the unwind happens, so the user sees that his item has been entered into the list. I have to use a refresh control in order for the table to reload its data.
Is there a method whose code runs once the part written in bold happens?
Thanks in advance.
You can reload your table view data in the viewWillAppear method of the UITableViewController, which is called every time your view appears on screen. You can see this question for more details on the view controller lifecycle.
So I'm really new to iPhone development and this is what I want to achieve. I want a search bar that uses a REST api that I've written to get back data and populate a table view.
In terms of what I've attempted - I'm not sure where to start, so I'll just post some thoughts.
What I've done is created three views - a root view, a search view and a results view. The root view should have a UISearchBarDelegate, an UITableView DataSource and an UITableViewDelegate because there needs to be a controller that can execute the search and populate the table.
However I'm not sure if this is the right approach, or even where to go next after this.
I know I should probably try more code, but I'm just really not sure where to start because this is an architecture thing - I'm not sure where the data will be passed between search and results(I think this should be in the root view) and how that root view will know when the search is done.
Thanks
You can do this all in one ViewController. Make it a delegate to the UITableView and the UISearchBar, as well as the DataSource for the tableview. Put the searchbar in a UINavigationBar along with a button with the text "Search". When the button is pressed take the text in the search, send it to your REST api, then set the data as the DataSource. Then just call [tableView reloadData] and the view will refresh with your updated data.
in my iOS application, i'm wanting to present the user a table of items using a UITableViewController, have them select an item, then return that item back to the another view controller. i can do this successfully by defining a protocol and delegate method for the table view controller, presenting the table view controller modally, then dismissing it when the user selects an item and returning the item to the delegate view controller. but, if i also implement a search display controller for the table view (so the user can search for a specific item in a longer list) i run into a memory issue. i've modified apple's 'TableSearch' example to demonstrate this, and have posted the code at https://github.com/pistachionut/Table-Search-Example
in short, the app usually crashes with an EXC_BAD_ACCESS just after selecting a cell in the table view. running it with NSZombieEnabled is indicating that the table view controller is being called by -[UISearchDisplayController _destroyManagedTableView] after its retain count has reached 0. anyone have an idea why this is happening? i don't think i'm doing any additional releasing of the table view controller beyond what i'm responsible for. i create it using alloc and initWithNibName, present it modally, then imediately release it (see -(IBAction)showProductPicker:(id)sender in the 'PickProductViewController.m' file in my example). thanks!
the answer posted by Jeff to How can UISearchDisplayController autorelease cause crash in a different view controller? solves the problem.