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];
}
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 have a Tab Bar application with 6 Tab Bar items that each open a UITableView. I am trying to enable each table with the ability to open a Detail View Controller when an item in a row on the table is selected.
For example, for the first ViewController ( ViewController1.m ), I created
DetailView1.xib
DetailViewController1.h
DetailViewController1.m
In order to get each row in ViewController1.m 's TableView, I understand I must
use this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
This is my code for that method, which does not produce any errors or warnings, but nothing sees to happen when the TableViewCell is selected:
DetailViewController1 *dvController = [[DetailViewController1 alloc] initWithNibName:#"DetailView1" bundle:[NSBundle mainBundle]];
[navController pushViewController:dvController animated:YES];
[dvController release];
Should this not load DetailView1.xib? I created this with the Tab Bar Application Template...which has no NavigationController in it by default I believe. Is it possible something is not hooked up right in Interface Builder?
You'd need to configure each tab to contain an instance of UINavigationController with one of your view controllers nested inside of it. Then in tableView:didSelectRowAtIndexPath:, you'd want to change the second line of code in your example to this:
[[self navigationController] pushViewController:dvController animated:YES];
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
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'm trying to create an application for the iPhone with a table of categories. If I select a category it will display a UIImage. However, I've been looking into it and I'm not sure exactly what to do. Can anyone lend a hand?
It sounds like the easiest solution would be to use a UITableView in a Navigation Based Application.
(Apple has samples on how to use this)
Load the table with your categories.
When the user selects a category, push a new View from a Nib file onto the navigation stack.
This will allow you to use the same Nib for all categories and you just pass the image to load to the class, which handles loading it into a UIImageView.
For example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
imageCatView *catView = [[imageCatView alloc] initWithNibName: #"imageCatView" bundle: nil];
catView.categoryID = [[[categories objectAtIndex: _selectedRow] objectForKey:#"CatID"] intValue];
[[self navigationController] pushViewController:catView animated:YES];
[catView release];
}