UINavigationController, UITableView and not showing the next view - iphone

I am having a problem with a table and showing another view when the user touches a table cell. I am using a UITabBarController for the main view to show different views. I then use a UINavigationController when the user selects a UITableView view to display the next view from the table cell selection.
My problem is this: when they select the table cell, the cell is highlighted and the next view does not appear. I am using IB. All of the examples I have found are doing this the same way I am, except the examples work!
I have the controllers loaded in a NSMutableArray with a Dictionary. I also tried this code by directly creating a view controller rather than using the array item. Same results....
I checked the target controller (Calc1ViewController) to make sure there was nothing wrong with the controller. When showing it directly, the controller (Calc1ViewController) displays correctly.
Here is some code.....
The initialization of the view controller in the dictionary:
Calc1ViewController *calc1ViewController = [[Calc1ViewController alloc] init];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(#"SSC - page 1",#""), #"title",
calc1ViewController, #"viewController",
nil]];
[calc1ViewController release];
I also tried this without using the dictionary -- creating a view controller in place of the [[menuList objectAtIndex:...]; line -- by creating the view controller like this:
Calc1ViewController *targetViewController = [[Calc1ViewController alloc] init];
// the table's selection has changed, switch to that item's UIViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *targetViewController = [[menuList objectAtIndex: indexPath.row] objectForKey:#"viewController"];
[[self navigationController] pushViewController:targetViewController animated:YES];
targetViewController = nil;
}
The navigation controller is defined in the AppDelegate and connected to the RootViewController through IB.
When I select a table row, it shows in the debugger that the pushViewController code is executed, but the next view does not show. Here is an example:
alt text http://thecoolestcompany.com/ssc-table-view.jpg
Any ideas?

Finally figured it out......
I had the UINavigationController and the UITabBarController on the same level. After moving the Navigation Controller as a child to the tab bar controller, everything worked. You may add as many navigation controllers to a tab bar as you would like. In IB is is a little confusing. You need to drag the NavigationController into the TabBar to as it as a new Tab Bar item.

Theres not much to go by with t he code you have provided. Only thing i can think of without looking at more code is that perhaps you have not initialized your view controller (the one in your dictionary) correctly, or at all, or the dictionary you are accesing there is not the correct one...

What is the value of [self navigationController] when pushViewController is called. Is it nil?
What is the value of targetViewController when it is passed to pushViewController. Is it nil?

Related

Adding detail view to UITableView

This app is my first app using a UITableView, and I've run into issues why trying to add a detail view to it. (because I made my app a "View-based Application" when I first created it, I have to do this manually).
This is the code for my didSelectRowAtIndexPath: of the table view:
detail = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle: [NSBundle mainBundle]];
detail.delegate = self;
detail.dtitle = [titles objectAtIndex: indexPath.row];
detail.dusername = [usernames objectAtIndex: indexPath.row];
detail.dpassword = [passwords objectAtIndex: indexPath.row];
[self.navigationController pushViewController: detail animated:YES];
//[self presentViewController:detail animated:NO completion:nil];
The second to last line is the one causing problems. I copied it from a blank "Master-Detail Application" that I made, but it doesn't seem to work in this app as it does in the other. The commented out line is what I've been using in it's place, but isn't exactly what I want.
What can I do to fix this?
Secondly, in theDetailViewController, the back button in my title bar (the navigation item of a navigation bar, to be precise) just will not appear. Is there code I have to add to indicate that this view is a subordinate view or something?
In order to push another view controller using the nav controller, there actually needs to be a navigation controller. Is "self" in a navigation controller?
If not, create a navigation controller setting its root view controller to the first view controller. If the first view controller is your app's root view controller, now make the navigation controller the root view controller instead.
Once that is in place you can call [self.navigationController pushViewController: detail animated:YES];.

Acting on didSelectRowAtIndexPath during UISearchDisplayController

I have a UIScrollView that contains a UIImageView and a UISearchDisplayController. When the user taps on the image, the search display controller appears. I’m filtering a list based on the search text and the table associated with the UISearchDisplayController is correctly updated. When the user taps on an row in the table, I am receiving the didSelectRowAtIndexPath. That’s what is working. (I used this tutorial to help me implement the UISearchDisplayController.)
However, I can’t figure out how to (a) remove the UISearchDisplayController (i.e., the search box and table) from within didSelectRowAtIndexPath and (b) how to pass information about the row that was selected to the UIScrollView.
Thanks.
A) You should be able to dismiss the UISearchDisplay Controller with something like:
[searchDisplayController setActive:NO animated:YES];
B) I am assuming you are launching a new view controller to display information about the row selected? If so, do something like this:
MyViewController *viewController = [[MyViewController alloc] initWithNibName:#"myNibName" bundle:nil];
MyObject *object = [allObjects objectAtIndex:indexPath.row];
// pass object to view controller's "object" property
viewController.object = object;
[self.navigationController pushViewController:viewController animated:YES];
Sorry if anything is out of syntax, didn't type into xcode.

How to nest a navigationController inside of a UIPopOverController?

There are actually three views at play. My homeView, which is where I launch the picker from, which sets the StudyPickerController view as root to a navController, which is then presented inside of the popOverController. Then from within the StudyPickerController view, I need to push to the ScreenPickerController, a different view completely.
I have a UIPopOverController that is displaying the contents of a view that is a tableView. I would like to be able to push a new view with a viewController inside of this view, but as I will discuss, it is really close, but it just won't push!
So from my homeView, when the button is pushed, an action is called and this code is run:
self.studyPicker = [[[StudyPickerController alloc] initWithStudyArray:self.studyArray ViewNum:butto.tag] autorelease];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.studyPicker];
_studyPicker.delegate = self;
self.studyPickerPopover = [[[UIPopoverController alloc] initWithContentViewController:navController] autorelease];
[self.studyPickerPopover presentPopoverFromRect:CGRectMake(120,45, 10,10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
And this works pretty well! The popOverController displays the contents of my StudyPickerController without any problems. I get the feeling that I am indeed getting access to my navigationController because the frame of the popOverController has a bar at the top, instead of just being a thin border, it has a navigationBar.
So now when I want to select a row in this view, I would like to push to a new view, also with a tableView, with my navigationController. This is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray * array = [_studyArray objectAtIndex:indexPath.row];
ScreenPickerController * picker = [[ScreenPickerController alloc] init];
picker.seriesGUID = array;
picker.viewNumber = viewNumber;
[self.navigationController pushViewController:picker animated:YES];
}
It seems to me that this should be working! But alas, I press a row, and it highlights, and nothing happens.
I've been working on this all day, so it very well could be that I am just missing something, but I don't know what it is. Any help is appreciated
It seems there are two classes involved here: your homeView class and the StudyPickerController. I'm guessing the tableView:didSelectRowAtIndexPath: method would be in the homeView class?
In that case, self.navigationController is trying to access the navigation controller that homeView is in, not the navigation controller you put into the popover. Since homeView isn't even in a navigation controller, the accessor returns nil.
Instead, you will want to use something like [self.studyPicker.navigationController pushViewController:picker animated:YES];.

A couple of problems customizing Apples MultipleDetailViews Example

I have been trying to add/implement this example to my existing Split View app tests.
Apple Example
I what to use the concept of replacing the detail view or right view, otherwise my app will be different. It is this difference that is causing my problems.
I have a rootviewcontroller or left view and upon choosing something here a new view is pushed onto this view. Upon choosing something in this "pushed view" I want to change the detail view or right hand view. This is the difference to apples example where the rootview does not have a pushed view on it and thus references are not broken.
Below is my change code - the new View DVCases is being initialized but the didload is not happening.
The issues are learner issues to do with my classes.
This below code is in my RootViewController implementation code but my reference to splitviewcontroller is not working if there is a new view pushed.
Second self.navigationcontroller is not correct because I have pushed a second view to the rootviewcontroller.
To centralize and simplify the code what I have done is from the delegate of the pushed view in the didselect event i call a method found in the rootviewcontroller passing the index as a parameter. The code for my custom method contains what is below.
So my question is how do I do this in my situation where I have pushed other views onto the rootview or left side. It appears that after pushing a view the reference to splitviewcontroller is gone and self.navigationcontroller is also gone/or wrong.
UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
if (value == 0) {
DVCases *newDetailViewController = [[DVCases alloc] initWithNibName:#"DVCases" bundle:nil];
detailViewController = newDetailViewController;
}
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
[viewControllers release];
// Dismiss the popover if it's present.
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
}
// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (rootPopoverButtonItem != nil) {
[detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}
[detailViewController release];
I would appreciate any tips or help you might have.
Initialization of any viewcontroller class does not mean that it will make call to viewDidLoad method.
viewDidLoad method will only be called when you load view of that viewController. Generally we do it either by following methods.
1. Pushing it on navigation stack.
2. Presenting it using modal transition.
3. Adding it on some other view using [someView addSubView:controller.view];
4. Selecting any tabBar item for the first time Or tapping tabBar Item twice.
there may be some other scenarios.
But right now in your code I don't see any of this element.
Initialization means you are calling the direct method for intialization(calling its constructor) like here in above code initWithNibName will call this method of DVClass not any other(until this method had call for other methods inside it).
Thanks
As I am learning to properly code - my problems centres around that.
The above code is perfect as long as you call it using the same instance. I was not. Thus it was not working.
In the end I made my RootViewController a delegate for a method that has the above code. Thus when in another view - this view can call this method and the proper or real instance of RootViewController will implement it.

button does not show up in navigationBar item

I've created a project with Navigation-based Application template, and did some work and ran it.
I expected if I touch a cell, new view will show up and new icon (which is going back button) will show up on navigation-bar item too.
But for some reason, the 'back button' is not added automatically. What can be the problem??
Below is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
MessageView *detailViewController = [[MessageView alloc] initWithNibName:#"MessageView" bundle:nil];
NSDictionary* aMessage = [m_tableData objectAtIndex:indexPath.row];
detailViewController.m_message = [[NSDictionary alloc] initWithDictionary:aMessage];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
You probably haven't given your parent controller a title (just self.title = #"my name" in viewDidLoad or viewWillAppear). That's what gets filled in by default in the back button, so if you don't name it, you don't get a back button.
You are saying that MessageView is inherited from UIView. But I think if there's no problem to push into the navigation controller then it would be UIViewController's subclass.
There are some reasons for not displaying back button:-
1.) As Mackworth told that you have not given any title from which you are navigating.
2.) your Navigation Bar's back button property is set for hidden.
Otherwise back button should be appear on the navigation bar.
It seems you haven't set your Navigation Bar Title in the View from where you are navigating...
Once you set the title of navigationbar by default it will show you the back button
Use it in either ViewDidLoad or ViewWillAppear.
self.navigationItem.title=#"Set Your Title here";