Is it possible after selecting a cell in the table view and hitting the back button on the following view controller to arrive at the same place in the table? I don't like how it goes back to the top, especially because of the size of my table.
You should get the last touched index for the cell, and use
[tableView scrollToRowAtIndexPath:DESIRED_INDEXPATH inSection:indexPath.section]
atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
When you return to your previous view controller.
#ravi was right. Normally, the position of cell in table view won't change after pop up from decedent view controller. I'm afraid you setting up the table view in viewWillAppear what cause the table view to be recreated or reloaded everytime the view appear. If there some code inside viewWillAppear, try moving them to view did load.
Related
My storyboard that has the UISplitViewController as the initial view controller. Its master view has a UITableView embedded in a navigation controller, and there is a detail view controller which contains a MKMapView. Clicking on the table cell of the first table view segues into second table view controller.
Clicking on the cell of the second table view segues into second detail view, which is an image view. The segue type is "Replace" with the destination of "Detail Split". Basically, it loads up the image related to the row in second tableView in the detail view.
I am able to navigate back to my first tableview fine. I want to display the first detail view
when the first table view shows up. The reason being that it displays a map view which is related to the contents of the table view. I read quite a bit about it but did not figure out on how to do that. Your help will be really appreciated.
Have you tried adding the following to your first TableViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// existing code if you have any
[self performSegueWithIdentifier:#"Segue ID for your map" sender:self];
}
I have a table view in one of my view, I scroll down to the bottom of the table and then if I load another view which also has table view, Table view is not changing its position.
For Example:- If i am scrolling my table to its bottom and from there if i navigate, the new view having table view shows me bottom of table.
Instead I need to show the top of the table.
Please suggest me,earlier it worked fine in< iOS 5.
Thank you
Narasimha
When You push the view
In view will appear try
-(void)viewWillAppear:(BOOL)animated {
[self.tableview selectRowAtIndexPath:Nil animated:YES scrollPosition:UITableViewScrollPositionTop];
}
Hope this helps.
I am making an app where in if I tap on a cell of a table, I get navigated to another view. I am posting some data on that page but when I tap on the back button, the records are not updated. I understand it is because, I get the same view from the navigation controller. Can you suggest me a way to reload the data content in this case
In viewWillAppear:animated:, try this:
[tableView reloadData];
I have a navController and tableViewController set up such that selecting a table row will push a detail view on the navController's stack and display detailed information about the row selected. In the detail view I use a single UILabel to display the info, and I set the value of the label's text property in viewDidLoad of the detail view controller.
The first time I select a row, the detail view comes up with the expected text. When I go back to the table view and select a different row, the detail view comes up with the same text as the first time.
I have seen some code samples where the detail view controller is released and then set to nil after being pushed on the navController's stack. If I add that to my code, the problem goes away, but I don't understand why.
Can someone explain to me what's going on here?
Thanks!
-viewDidLoad is called only when the... well, when the view is loaded. That is to say, when it is created in memory, which is the first time you create the view controller. Any customizations based input data should be done in -viewWillAppear: instead, which gets called every time before you push it onto the navigation controller.
Although, in general practice, I always release a new view controller immediately after pushing it onto the stack, since it doesn't belong to me any more, it belongs to the navigation controller. In this case, the next time you push it on to the stack, it will load the view again, since it's a new object.
- (void) tableView:(TableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *screen = [[MyNewViewController alloc] initWithData:[data objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:screen animated:YES];
[screen release];
}
The main idea, though, is that customizing a view based on data that may change every time you see the view should be done within -viewWillAppear:. Customizing a view further than you can in Interface Builder, changing things which won't change no matter what data you're looking at, should be done in -viewDidLoad
I have a UINavigationController that gets UIViewControllers pushed onto it. In the first view there is a grouped table view which has 3 rows, each containing a UITextField with initial text set on viewWillLoad of that view controller. Tapping any one of the table view cells pushes the 2nd UIViewController onto the nav controller's stack. Each of the secondary view controllers has another table view where the user can select a choice by touching one of the rows.
The experience is identical to the iPhone's ical, when selecting "repeat" for an event.
The problem is that when the user touches the UIBarButtonItem to save, and I set the selected value into the previous views text field, the text field doesn't update. Regardles of what text I set it doesn't update when the navigation controller pops back to the first view. Could it be cached, or the view cached as a whole?
I'm logging all the values and everything looks correct.
Sorry to not post any code, I'm not sure how to without posting a book.
You could do a reloadData when the main view reappears. This forces the table to refetch the visible rows and redraw them.
[theTable reloadData];
Edit: an improvement would be to only reload the row affected, instead of reloading all the visible rows with the reloadRowsAtIndexPaths:withRowAnimation: method.