I can post code, though I'm not quite sure where to start. I have a UITableView with custom cells, in the middle tier of a three-level UINavigationView scheme. When I drill down to the bottom level and see details about my data, then use the top-left back button, my table view comes back scrolled all the way to the top, rather than scrolled down to where it was when I last saw it. Where should I look about this?
EDIT:
Here's the code in the EventsTableViewController to load an instance of EventsDetailViewController and push it on the navigation controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *events = [DataManager sharedDataManager].eventList;
Event *selectedEvent = [events objectAtIndex:[indexPath row]];
EventsDetailViewController *detailController = [[EventsDetailViewController alloc] initWithNibName:#"EventsDetailView" bundle:nil];
[detailController loadEvent:selectedEvent];
MyAppDelegate *del = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
[del.navigationController pushViewController:detailController animated:YES];
[detailController release];
}
There's nothing in my EventsTableViewController about reloading the table, as far as I can see--I haven't implemented viewWillAppear or viewDidLoad or any of those.
Are you by any chance reloading the table where you shouldn't be? In the ViewWillAppear method for example?
I was accidentally instantiating a new copy of my table view whenever I hit this level of the navigation. That's all fixed now and this isn't a problem anymore.
I have a very similar question. When I go to the chatView, which is a UIViewController belonging to the navigationController and has a tableView as a subview, and then I scroll to some point, and then I go back, and then I go back to the chatView, it starts at the top again. I am allocing the tableView in loadView of the chatView, so the tableView gets realloced everytime I come back. But, isn't this standard? How do I just always scroll to the bottom like the iPhone Messages app and show the scroll bar for a few seconds at the bottom?
Here's the code:
http://github.com/acani/acani-chat/blob/master/Lovers2/Classes/ChatViewController.m#L184
Thanks!
Matt
are you doing:
[self presentViewController:navController animated:YES completion:nil];
where self is tableviewcontroller? give this a try:
[self.navigationController presentViewController:navController animated:YES completion:nil];
Related
I'm presenting a modalViewController with UIModalTransitionStyleCoverVertical and then, when the user selects a row of this modalView, I present another modalView as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CenterViewController *nextView = [[CenterViewController alloc] init];
nextView.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:nextView animated:YES];
[nextView release];
}
The problem is that the transition style remains UIModalTransitionStyleCoverVertical no matter what type of transition style mode I initialize for this second modal view controller.
Am I missing something relevant?
Thanks in advance.
UIModelPresentaionStyle is used to tell iOS you want it FullScreen or PageSheet..etc. , in your case you should use UIModelTransitionStyle .. so if you did like this it should work.
nextView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
I'd try removing the old one first, and then presenting the new one.
Doesn't sound like a great technique though. Why not have you first modal view controller be some sort of container controller, and present the new view with a flip.
losing sleep over this issue
My app hierarchy is ListVC1-->ListVC2-->DetailVC. [Working perfect]
and... SearchListVC-->DetailVC (the same DetailVC as above) [Issue is in this model]
The code in SearchListVC is almost same as ListVC2, with a difference that it contains a SearchBar, instead of a navigationBar, on top.
Also, please note that I am able to present the DetailVC as a ModalView, it is push that is not happening... the cell remains highlighted.
Here is the didselectrow code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Navigation logic may go here. Create and push another view controller.
if (indexPath.row<[smses count]) {
WebSMSDetailViewController *detailViewController = [[WebSMSDetailViewController alloc] initWithNibName:#"WebSMSDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
detailViewController.smsList = allWebSMSes;
detailViewController.smsIndex = indexPath.row;
[detailViewController populateDetails];
[detailViewController release];
}
else {
if (indexPath.row<totalSMSes) {
pageNumber++;
[self loadNotes];
}
}}
I think the problem is somewhere else.
I have been googling for quite a while but couldn't understand the solutions posted, so please be a little descriptive... beginner here!
I suppose the problem is that, you dont have a navigation controller in the SearchListVC.
Like you wrote,
it contains a SearchBar, instead of a navigationBar, on top
Use a navigation controller with the SearchListVC and I think your problem is solved.
Cheers
You just create/use #property for the navigationBar
or u have to place the Navigationbar on the top of the view and place your search bar on the bottom of the navigationBar
I just filled my UITableView with Planets. I would like each cell clicked to open into a new Xib (if this sounds like the wrong approach please direct). I can get a secondviewcontroller working, its getting the thirdviewcontroller and fourthviewcontroller working? Thanks.
Place your main view controller (the one with the table) inside a UINavigationController. Then, when the user selects a row, push a new view controller onto it.
The following function will help. As Ben Gottlieb said your main view controller will need to be in a UINavigationController. You need to implement the delegate method for didSelectRowAtIndexPath and this is where you create the new controller for your new view and load it.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
YourViewController *controller = [[YourViewController alloc] initWithNibName:#"YourViewController"bundle:nil];
[[self navigationController] pushViewController:yourViewController animated:YES];
[yourViewController release]; // don't leak memory
}
Based on the row number you can decide which nib to load.
I have TabBarView Controller, where i keep four tab bar items, let sat item1, item2, item3 and item 4.
When clicking on item2 tab bar item, i call a RootViewController where it has a Navigation controller with a TableView and shows the row items.
Upto here it is fine.
When clicking on a row item, will have to launch a UIWebView to show the content.
I did code like below for this process.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
navigationController = [[UINavigationController alloc] init];
webViewController = [[WebViewController alloc] init];
[[self navigationController] pushViewController:webViewController animated:NO];
[webViewController release];
}
The problem now is, clicking on a row item is not pushing the UIWebView code at all. I tested the UIWebView code with normal addSubView method like
"[appDelegate.window addSubview:webViewController.view];"
instead of calling via pushViewController. It is calling UIWebView and shows the web content successfully.
I understand the problem should be calling as pushViewController:webViewController.
Can anyone point me what are the ways that it should be not be worked in this case and how can i correct it to make it work with pushViewController itself? I need to call UIWebView only using pushViewController.
For such all these combination, is there any sample source available?
Waiting for someone's help.
thanks.
Clave/
I think you are mistakenly creating a new navigation controller here
navigationController = [[UINavigationController alloc] init];
remove that line and use
[self.navigationController pushViewController:webViewController animated:NO];
instead of your reference above. That should do it :-)
I have a tabbed bar main window with four tabs, one of which is a list. This list is empty at first but when I click a "+" I am presented with a modal view of available options like this
- (IBAction)addThing:(id)sender {
MJAvailableThingsViewController *controller = [self availableThingsViewController];
[self presentModalViewController:availableThingsViewController animated:YES];
[controller setEditing:YES animated:NO];
}
This works.
The list of things has a UITableViewCellAccessoryDetailDisclosureButton on each row. This was done with the accessoryTypeForRowWithIndexPath. This works as well.
When I click the little blue button in this view the delegate accessoryButtonTappedForRowWithIndexPath is called. This works.
However, in accessoryButtonTappedForRowWithIndexPath I want to present a detail view of the thing and this is where I encounter problems:
The delegate looks like this:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
{
NSLog(#"accessoryButtonTappedForRowWithIndexPath");
NSLog(#"Tapped row %d", [indexPath row]);
[[self navigationController] pushViewController:thingDetailViewController animated:YES];
The program enters this code but nothing happens, that is I get the NSLog output but no new window. I am very new at this so please forgive me if this is obvious; to me it is, however, not... :-)
Do you have a navigationController? It sounds like you have a TabController but not a NavigationController.
Check [self navigationController], is it set to anything?
Here's a similar question:
Tab Bar Application With Navigation Controller