iphone popviewcontroll problem - iphone

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
//Some code to go to the next page
NSString *selectedCountry = [arraycountries objectAtIndex:indexPath.row];
NSString *selectedCountry1 = [arycountries objectAtIndex:indexPath.row];
profilepage *detailViewController = [[profilepage alloc] initWithNibName:#"profilepage" bundle:nil];
detailViewController.selectedCountry = selectedCountry;
detailViewController.selectedCountry1 = selectedCountry1;
// ...
// Pass the selected object to the new view controller.
[self.navigationController popViewControllerAnimated:YES];
[detailViewController release];
This is my code,how can i pass selectedCountry and SelectedCountry1 to profilepage,,,
i try but,i didnt get any values, please help me,thnkzzz

If detailViewController is the next view, you should be using pushViewControllerAnimated:animated: instead of popViewControllerAnimated:. Logically, push goes forward and pop goes backward.
The navigation stack is described in the Navigation Controllers section of the View Controller Programming Guide.
[self.navigationController popViewControllerAnimated:detailViewController
animated:YES];
[detailViewController release];

Related

Back bar doesn't show up in navigation controller

Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:#"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
[DrinkDetailViewController release];
}
I want to have a back bar to go to my root view from the detail view. How do I do it?
There's 2 things that look a little weird here... hopefully fixing em will make the back btn show up:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:#"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
//[self.navigationController popToRootViewControllerAnimated:YES]; <-- you just pushed a viewController onto the stack, and you're immediately removing it here and going to the root
[detailViewController release]; //<-- you want to release the *instance* that you created... not the Class
}
The UINavigationController should take care of the back button for you as far as I know. If not, I would check to see that everything is wired up correctly in your xib (if you have one). Good Luck!
With your code, it will still push to the DrinkDetailViewController but the' popToRootViewController is totally unnecessary. You should delete the line like follows..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:#"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
And I believe, the reason your back button does not show up on the nav bar is because you didn't put any title in your root view. You can put this code on you viewdidload method on the root view.
self.title = #"Your Title";

How to push a view, go back and come back to the view?

I want to build an app for playing local audio files on the iPhone but I'm stuck with some of my codes.
I'm wondering how you can push a view, come back to the uitableviewcontroller and use a button ( like the "NOW PLAYING" button in the media player) to come back to the view without pushing any new string into it..
THANK YOU
What should I change from my codes ?
in the uitableviewcontroller..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
selectedSong = [directoryContent objectAtIndex:indexPath.row];
NSString *storyLin = [[directoryContent objectAtIndex:[indexPath row]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
patch = [NSString stringWithFormat:#"/%#", storyLin];
myDetViewCont = [[mPlayerViewController alloc] initWithNibName:#"mPlayerViewController" bundle:nil];
myDetViewCont.myProgLang = selectedSong; // assigning the correct value to the variable inside DetailViewController
[self.navigationController pushViewController:myDetViewCont animated:YES];
[myDetViewCont release]; // releasing controller from the memory
}
in mPlayerViewController.m
-(IBAction) backtoplayer{
myDetViewCont = [[mPlayerViewController alloc] initWithNibName:#"mPlayerViewController" bundle:nil];
}
If you have pushed a view onto the navigation controller, just pop it to review the view underneath.
That is, the view you push myDetViewCont should just be popped in the backtoplayer call.
- (IBAction)backToPlayer:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
To Add to what Mark said.
Once you've popViewControllerAnimated and the user want to push the same controller again, you just need to keep the mPlayerViewController rather than release it.
Such as:
if (!myDetViewCont)
{ // We only need to create it once.
myDetViewCont = [[mPlayerViewController alloc] initWithNibName:#"mPlayerViewController" bundle:nil];
}
myDetViewCont.myProgLang = selectedSong;
[self.navigationController pushViewController:myDetViewCont animated:YES];
// no longer release here, move the release call to the dealloc

Back button isn't getting displayed upon pushing a controller into the stack

I created iOS application from Navigation-based application template.
This snippet is from RootViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DotoViewController *detailViewController = [[DotoViewController alloc]
initWithNibName:#"DotoViewController" bundle:nil];
NSManagedObject *selectedObject = [[self fetchedResultsController]
objectAtIndexPath:indexPath];
detailViewController.dotoObj = selectedObject;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
DotoViewController is a subclass of UIViewController and has an accompanying NIB file.
Upong clicking on a row, DotoViewController is getting displayed but without the back button to RootViewController on the left side.
What I'm missing?
Perhaps your root view controller has an empty title? The view controller's title is used as the title for the back button, so if you have an empty string there, this can cause the back button to disappear. If it's nil, it should display the standard "Back" though.

How to open a new UITableView when clicked on a table cell and add navigation controller dynamically

Basically I add a subview to the main window. This subview has a search bar and a table view. The search bar works and it displays some data on the table view cells. Now when I click on a cell it should load another view with a navigation bar (w/ back button) and a table inside that view. How can this be done? I tried the following code and it doesn't work, it gives me an error saying - "'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "DetailViewController" nib but the view outlet was not set.'
I tried to set the outlet's in the DetailViewController.nib file but it just wouldn't let me.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[UITableViewController alloc]initWithNibName:#"DetailViewController" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}
Basically you push the detail view controller onto the navigation controller.
I published a sample code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailContactViewController *detailViewController = [[DetailContactViewController alloc] initWithNibName:#"DetailContactView" bundle:nil];
detailViewController.contact = [contacts objectAtIndex:indexPath.row];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}

Change to another view from tableview with a navigationcontroller placed in a tabbarcontroller

I recently found a good tutorial about how to place a navigation controller within a tabbarcontroller("The nib way").
http://twilloapp.blogspot.com/2009/05/how-to-embed-navigation-controller.html
I continued with the second step and added a tableviewcontroller to the navcontroller.
What I don't understand, is how I can use the navigationbarcontroller from within my tableviewcontroller and e.g - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
What I want to do is when a user selects a row another view should slide in with the back button and everything that a navigationcontroller provides.
Thanks in advance!
Have you started with Apple's SimpleDrillDown sample? The specific code in question is this routine:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
Create the detail view controller and set its inspected item to the currently-selected item
*/
DetailViewController *detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
detailViewController.detailItem = [dataController objectInListAtIndex:indexPath.row];
// Push the detail view controller
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
}
The following was what I was looking for:
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
Since I've specified the RootView Controller for my NavigationControllers View, self answers to navigationController.