iphone uitableview to another view - iphone

in my program I need a tableview and, when you click onto a row, the view scroll left and show the details (like the mail for example...)
how can I do this??
I explain... it's an automatic thing or I need to manage by hand the animation of the view??
thanks in advance

I use UINavigationControllers to achieve this effect of the detail animating left when you click on the row. So you need a UINavigation controller above the UIViewController or UITableView Controller that controls your table.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...my code
[self.navigationController pushViewController:myViewController animated:YES];
}

Your case is exactly what UINavigationController class is for - it will handle your controllers hierarchy and will do animated transition for you as well. To learn how to use it you can have a look at Apple's NavBar sample.

Related

Adding a Navigation Controller to a Tab Bar Application (Programmatically)

This might look like a silly question to some, but handling the different types of controllers in an iPhone application is still a little fuzzy to me. Here's the setup:
I have a Tab Bar application with four tabs. Each tab passes control to its respective ViewController, where some of those are initialized with a .XIB file and some are done purely programmatically. One of the programmatic ones is DirectionsViewController, which is essentially a UITableViewController. Selecting a cell from its table needs to present (modally) a DetailedDirectionsViewController, which needs to have some sort of back-reference to the presenting view controller. I figured the easiest way to do this is to add a navigation controller to the Directions and DetailedDirections VCs - except I don't know how to do this without a .XIB file.
Also, the way I hand control over to DetailedDirections is by changing Directions the following way:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailedDirectionsViewController *vc = [[DetailedDirectionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.tabBarController presentModalViewController:vc animated:YES];
}
I seem to recall one of my professors saying that presentModalViewController is kind of an old method and there are better alternatives... I just can't remember them right now.
For what you want to do it would be best to have the tab in your tabbar manage a UINavigationController, and to set the rootViewController of that navigation controller to your DirectionsViewController.
Then in your direction view controller's didSelectRowAtIndexPath: methods you can do the following:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailedDirectionsViewController *vc = [[DetailedDirectionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:vc animated:YES];
}
And it will function like you want it to. The UINavigation controller will take care of putting a back button on your detailed directions view controller.
If I understood well, in the tableview:didSelectRow..: you just need to create a navigation controller initializing it with the view controller that you want to display modally, before presenting it create a UIBarButtonItem and add it to the navigation bar of the navigation controller as selector create a new method with the dismiss command inside.

storyboard segue from a tablecell an its Detail Disclosure Button

I want to segue from a tablecell to two different viewcontrollers
if clicked in the cell or clicked on the cells Detail Disclosure Button.
If I ctrl-drag the second segue, the first is deleted.
What am I doing wrong?
Tnx
Mica
I don't think you can link a specific detail disclosure button w/ a segue. My storyboards are extremely programatic b/c I use alot of custom CGRect etc..
so I tend to use something like this:
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"ViewControllerIdentifer" sender:self];
}
for reference this is an extremely good example project on storyboards and tableviews. there's a link to the project at the bottom also.
http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2

app with tab bar and navigation bars

Hi all,
this is a typical layout of one of apps. Now what I want on clicking of row of one of the view controllers(table view), I want to change the index of of the tab. Lets say I am in 3rd view, I want to move to the 1st view.
I tried with navigation controller's didShowViewController delegate method. Seems its not working. Could you please suggest any other way to do this?
Thanks.
Just use the below code in didSelectRowAtIndexPath method of UITableView, then you just need to set the SelectedIndex for Tabbar.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
[self.tabBarController setSelectedIndex:indexPath.row];
}

Changing UITabBar during Navigation in iOS

When my app launches, it presents a navigation view with a tableview and a tabbar on the bottom.
Something like this:
TabBar --> UINav1, UINav2, UINav3, UINav4
Each UINav contains a ViewController that is eventually displayed.
What I want to be able to do is to change the UITabBar if the user moves from the ListView (Main screen) to the detail view.
I don't have to swap out the whole tabbar atleast change/remove the buttons.
However, if I use the above model (setting TabBarController as the root controller) then it seems it's pretty much stuck and immutable in the course of the navigation. The best I can do is just hide it in certain views.
Been banging my head for like a day trying to figure this out.
Thanks!
You could use
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
in your UITabBarController to set the tabBar whatever viewController you wish
EDIT: You might wan't to look at this question wish seems to be quite similar iPhone, how I hide a tab bar button?
It is not very common but you can present a new tab bar controller along with its associated view(s) modally.
Assuming your listView is a UITableViewController, you can push the new tab bar controller in your didSelectRowAtIndexpath method.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
[self.tabBarController presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated]
PS: I would be very careful with how you structure your UI in this case as it can get quite confusing for the user).
I hope it helps.
Rog
Upon further research, decided that this was not feasible to do.

Iphone -- push a view controller onto the navigation stack when a button is clicked in a UITableViewCell

When a button is pushed in one of my app's table view cells, I need to push a certain view controller onto the navigation stack.
This could be done by using an instance of NSNotification to inform the table view's controller of the button press. But that would be awfully heavyweight, especially since selections in a tab bar in the app could cause the table view to appear or disappear, creating additional overhead as the various table views register and unregister themselves whenever they are tabbed onto or off of the screen.
Can anyone think of a better solution?
Why not put
[[self navigationController] pushViewController:targetViewController animated:YES];
in the method called by the button?
Make your UITableViewController use the UITableViewDelegate Protocol and implement this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
From the indexPath you can get which row has been pressed and then you know which cell is being selected. The purpose of the UITableViewController is to know about the cells and the cell itself does not need a button to trigger an event to push a new view.
What I did was set the table view's delegate to be the same as its controller. Then:
UITableView *myTableView = (UITableView *)self.superview;
NSIndexPath *indexPath = [myTableView indexPathForCell: self];
MyTableViewController *myTableViewController = (MyTableViewController *)(myTableView.delegate);
[myTableViewController buttonWasPressedOnCellWithIndexPath: indexPath];