I have a nav controller --> table view controller --> view controller. The selected row returns a detail view. What I would like is when the back button is clicked the table scrolls back to the selected row rather than back to the top.
I have been through both SO results and google but after many attempts it fails, either achieving nothing or being declared as unassignable; I've tried assigning index path to property and content offset. I have all the common tableview methods. And I believe I require viewdidappear.
How do i achieve this?
Related
I have a collection view where each cell has a video (played through AVPlayer) and a red circle. When a button in the view controller is clicked, the color of all cell's circles should be changed to blue, and then if clicked again, changes it back to red.
So what I need to be able to do is: when the button is clicked in the controller view, change the circle view in all cells, visible or not. The reason I say visible or not is because I only show one cell on the screen at a time. The user swipes to go to the next cell.
I have already tried using reloadData() to update all cell's circles when the button is clicked, however, the problem I discovered is that the video resets back to the beginning (and I need it not to do that, not just for the visible cell, but for all cells).
What are my other options?
When a button in the view controller is tapped you would need to change the data/collection/array of data that you are loading in your collection view. In order to achieve the result in (for example didSelectItemAtIndexPath:(NSIndexPath *)indexPath) you should change the data model for that specific cell/collection item. You can add for instance property isSelected for your collection view data model(s).
In your case, calling reload data calls all the UICollectionViewDelegate & UICollectionViewDataSourcemethods, however since you have not change the data using, the result/UI returns to the initial state.
It seems that the default behavior of the UISearchController is to display an empty table as soon as characters are entered in the UISearchBar. The search I'm implementing doesn't search as the characters are entered, but it searches when the Search button is tapped.
Because of this, I don't want to display an empty table until the actual search happens. How do I make this happen?
I've tried to set the table hidden until the search button is tapped, but it doesn't seem like the empty table that appears is the same as the UISearchController table, because none of the datasource methods are called on that table.
The empty table view you are seeing is from your search results controller, which is "immediately" displayed by UISearchController "when the user enters text in the search bar". (source)
Hiding the table view in your search results controller until you are ready to show it would seem to be the easiest solution. But as you discovered, upon displaying the search results controller, UISearchController sets the value of the isHidden property on the root view to false. In my debugging session, UISearchController behaved this way every time the search bar began editing or the search text changed, by calling a private method named _updateVisibilityOfSearchResultsForSearchBar:.
You can work around that behaviour by adding the table view in the search results controller as a subview of the root view (and then hiding or showing the table view as necessary), or by adjusting the value of the alpha property for the root view (which, unlike isHidden, can be animated).
In this case, you can do work around like creating a UIView and adding as subview over the tableview to make it hidden. Once user clicks on search button remove that view.
I have only one view controller with collection view in page view controller and having search button on the navigation bar when i click on search bar and did search then the result is shown properly means child view controller is updating but when i slide it on left it also showing me the original content of collection view also. how can i remove that previous view controller and show only result child view controller.
Then you dont want a page view controller, A pageview controller will reuse the single child view controller each time the swipe is detected. In your page view controller delegate methods properly check the values from which it is being loaded is the array being reduced permanently or are u using a mutable copy of the array each time you reload the page view controller contents.
I answered a possible solution to a similar question. Maybe it will help you.
UIPageViewController keeping previous ViewController on the Background of the view
So I have a UITableView that navigates to a detail view when a cell is selected. Each cell and it's detail view passes through different data depending on which cell is selected. On the storyboard it is one generic detail view with a text label and an image view that loads in data from an array.
What I want to do is navigate from the current detail view to the next detail view (for the next item in the table) without having to go back to the main table view controller. How can I do this? I would like to do this with a button.
I have looked at this but I can't seem to get it right/not sure it's exactly the same thing: Navigate between sibling detail views of a parent table view
I have a UIViewController with an UITableView and a NavigationController to implement a drill down navigation system. The user can browse a hierarchy of folders and documents.
I am using a NSFetchedResultController for populate the UITableView from a data base.
I would like to add the option of browsing the hierarchy using a GridView (fe: AQGridView). The idea is to have a button on the navigation bar for switching between
tableView and gridView.
Problem/Question 1:
What is the best way for switching programatically from the controller with a table to the controller with a grid?
Problem/Question 2:
After switching, if there are other controllers pushed into the navigation controller,
and the user goes back, these view controllers will be presented without any change. How can I update these view controllers? For example: the user switches from table to grid, then goes back, and after pop the current controller, the user sees again a table -> wrong.
Where you display the top level of the hierarchy (the UITableView), you would want add a UITableView or a the grid view as subviews when requested.
You would add methods to your view controller:
-(void)displayAsGridView {
// hide/remove the table view
// populate the grid view and display
}
-(void)displayAsTableView {
// remove or hide grid view
// make sure the table view exists, if not, create it
[self.tableView reloadData];
}
In the table's data source:
-(UITableViewCell*)tableView:(UITaleView*)tableView cellForRowAtIndexPath:(IndexPath*)indexPath {
// you populate the view cell as you would for any other table
}
You can create both of those either in IB or entirely via code, whichever suits you best. The point is, you would not push either one of those onto the navigation controller just to rearrange how the information is displayed.