Pushing a new viewcontroller from a tableview in a tab bar app - iphone

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.

Related

navigation from tableview to another view

I am working in a table view app using story board . I want to perform event on selection
of cell in table view . So when I select a cell element , a next view(detailview) should be
open for displaying further details .
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.dv = [[Detail alloc]initWithNibName:#"Detail" bundle:nil];
dv.dic = [self.arr1 objectAtIndex:indexPath.row];
[self.view addSubview:dv.view];
}
Instead try this:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.dv = [[Detail alloc]initWithNibName:#"Detail" bundle:nil];
dv.dic = [self.arr1 objectAtIndex:indexPath.row];
[self presentViewController:dv animated:YES completion:nil];
}
And if you want to dismiss use this code:
[self dismissViewControllerAnimated:YES completion:nil];
You should use a navigation controller and when selecting a row, push the detail view into it.
To create navigation controller: selected the tableview controller and go Editor / Embed in / Navigation Controller.
Then do:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// dv = [Detail alloc] initWithNibName:#"Detail" bundle:nil];
dv = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
dv.dic = [self.arr1 objectAtIndex:indexPath.row];
[self.navigationController pushViewController:dv];
}
The commented line is if you're not using storyboard.
Or you can do as Abdullah suggested, but implement a dismiss button with
[self dismissViewControllerAnimated:YES completion:nil];
In the storyboard drag a segue from the viewcontroller icon at the bottom of your view to the next viewcontroller you want to segue to. Make sure that your view is embedded in a navigation controller. Press the arrow that appears between your tableviewcontroller and the target view controller and make sure you label it with a segue identifier. Then in the method you are describing make sure they selected the correct index path with an if statement and write
[self performSegueWithIdentifier:#"theNameOfYourIdentifierFromTheStoryboard"];
That being said, I think that there is a large body of information you should research.
Read this: http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/ as a start.

hiding tabbar on table view cell click

I have problem with hiding tabbar .
this my code
//this created in the Delegate.m file
-(void)HideTabBar
{
mTabController.hidesBottomBarWhenPushed =YES;
}
//Now i want to this on the cell select Tab bar must hide when it go to the map view (other view ) for that i use this but its working
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
JourneyAppDelegate * journey = (JourneyAppDelegate *)[[UIApplication sharedApplication]delegate];
[journey HideTabBar];
}
But
it work how can do this
mTabController will not get invisible/hidden until you push it for Example:
//this created in the Delegate.m file
-(void)HideTabBar
{
mTabController.hidesBottomBarWhenPushed =YES;
[self.navigationController pushViewController:IncomingViewController animated:YES];
}
//Now i want to this on the cell select Tab bar must hide when it go to the map view (other view ) for that i use this but its working
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
JourneyAppDelegate * journey = (JourneyAppDelegate *)[[UIApplication sharedApplication]delegate];
[journey HideTabBar];
}
You need to set hidesBottomBarWhenPushed property to the UIViewController that is going to be pushed before you call pushViewController.
As the method suggests, it works only as the view controller is pushed onto the stack. So instead of trying to hide it in the view controller, where the table view is, just add the line
[mapController setHidesBottomBarWhenPushed: YES] to wherever you create that map controller.
Hope you understand my workings.

TableView within NavigationBar within TabBar Navigation?

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];
}

iphone : SDK disclosure button not response from first TableView to second detail TableView?

How can I pass the first tableview row data to second detail view row
I use
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
or
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
to show up disclosure button in each cells
it can ,I also add actions in
- (void)tableView:(UITableView *)tableViewaccessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
NSLog(#"disclosure button %# touched",indexPath.row);
}
But when I touch the disclosure button I got nothing shows up in console
Than I add actions in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// carry Alarm Name text into sub-table-view to look for detail time and text info
NSLog(#"Alarm Name = %#", [alarmName objectAtIndex:indexPath.row]);
NSLog(#"Index Path Raw# = %i", indexPath.row);
// Navigation logic may go here. Create and push another view controller.
AlarmDetailTableViewController *detailViewController = [[AlarmDetailTableViewController alloc] initWithNibName:#"AlarmTableViewController" bundle:[NSBundle mainBundle]];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
detailViewController = nil;
}
It can notified on console mode
But I think it always appear the same detail view when I touch any rows in First Level TableView
How to show a new detail view with data from Level one ?
for example
To make the tableView1.row0.text = detail view.title
and show other data under the title
if you need the code I can upload it
my boss said it's not big secret inside...
Thanks a lot
Perhaps the problem is with your:
- (void)tableView:(UITableView *)tableViewaccessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
which should be reading:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
Ok,if you tapped on accessory button than show another detail view
we need to add a detail view
First create a "new navigation based application",ex FirstView
right click on the class folder and choice "add new File" choice a new view you wanna display
ex I selected a new tableview named "DetailView"
than first go to the DetailView.m go give a section and row numbers
or declare the layout
than back to FirstView.h
add #import DetailView
go to FirstView.m
find this method - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
and use DetailView sub class to create a new view
add the codes like this
DetailView *detailView =[[DetailView alloc]init];
detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:detailView animated:YES];
you can add any view you want to display

How do I make the rightBarButtonItem STAY when a view controller is pushed on?

When I push a view onto my view controller
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AnotherViewController *anotherViewController =
[[AnotherViewController alloc] initWithNibName:#"AnotherView" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
}
the RIGHT BUTTON ITEM of the navigationController DISAPPEARS.
Is there a way to make the self.navigationController.rightBarButtonItem STAY THERE like in the "Notes" application that comes with the iPhone?
I don't believe you can without using undocumented classes. However, if you set the rightBarButtonItem property to an item that looks the same, there shouldn't be a big difference.
You can do that with
self.anotherViewController.navigationItem.rightBarButtonItem = self.parentViewController.navigationItem.rightBarButtonItem;
after you´ve pushed the ChildViewController