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
Related
I've got an app with a UITabBarController that controls several UIViewControllers. Within that controller there is a UITableViewController. I'm trying to figure out how I can select a row on my tableview and push the view controller of one of my other tabs while actually navigating to that tab.
I've used performSegueWithIdentifier: but it pushes the new view onto the same tab that my tableview is in. I'd like to navigate to the tab that the view I'm pushing to is on.
In case I haven't been clear: My tableview is in Tab 1. I click on a row. I want to get to Tab 2. So far I've been able to push the view controller for Tab 2 onto Tab 1. No Good.
Can anyone shed some light?
Thanks
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger theIndex;
[self.tabBarController setSelectedIndex:theIndex];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *tab2ViewController = [self.tabBarController.viewControllers objectAtIndex:1];
NewViewControllerToPush *mvc = [[NewViewControllerToPush alloc] init];
[tab2ViewController.navigationController pushViewController:mvc animated:YES];
[mvc release];
}
When you enter the viewControllers in your tabBar, make sure to wrap them inside a UINavigationControllers, otherwise you would not be able to use push and pop functionalities.
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 am building an app with several levels.
First level are the Tabs on the bottom of the screen. (MainWindow)
Second Level is the content displayed with each tab in a TableView (Locations)
Third Level is the detailed overview of the selected item in the Second level content. (LocationDetails)
First and Second levels work fine. Now I want to create the content of the detailled overview. I have created a new NIB called LocationDetails.xib. It only contains some static text (an inserted Text View). So I can view the loaded window.
In the Locations.m file I have the following function:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString * locationCity = [[locations objectAtIndex:indexPath.row] objectForKey:#"city"];
NSLog(#"Your choice is: %#", locationCity);
Within this function I want to go to an other view (LocationDetails). What is the best way to go. If I haven't given you enough information, tell me! I can provide all the information you need!
Hope to hear from you soon!
With kind regards,
Douwe
I would use a navigation controller.
In your main xib file you would end up with something like this :
UITabBarViewController // Main Window
tab 1:
UINavigationController
UITableView // (Locations)
tab 2:
UINavigationController
UITableView // (Locations)
Then, the code to slide on your LocatonDetails is simple :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
LocationDetailsViewController = [[LocationDetailsViewController alloc] initWithNibName:#"LocationDetails" bundle:nil];
controller setLocation:[locations objectAtIndex:indexPath.row]];
[[self navigationController] pushViewController:controller animated:YES];
[controller release];
}
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];