cannot transition between view controller when clicking a table cell - ios

I want to transition from one view controller into another when clicking a table cell without any additional data passing. Here is a screenshot of my storyboard: http://imgur.com/C8yTRaZ
However, it doesn't go to the second view controller when I am clicking on the table cell. They are both embedded in the navigation controller (I think; since the "Navigation Item" is in both controllers). What am I missing?

Make sure you have mapped your table data source and table delegate to self.

For that you could use didSelectRowAtIndexPath in that you could programmatically call that other view Controller.
Like below:-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewController *viewController = [[ViewController alloc] init];
[self presentViewController:viewController animated:YES completion:nil];
}
This will help you out.

Make sure that 'user interaction' for both 'table view' and 'table view cell' should be enabled.

Related

Dismiss navigation controller and all of its view controllers stack in UIPopupview using a button within one of the views

I am displaying a UIPopoverView using the code:
selectClientPopController= [[UIPopoverController alloc]initWithContentViewController: [self.storyboard instantiateViewControllerWithIdentifier:#"navControllerMini"]];
selectClientPopController.popoverContentSize=CGSizeMake(500, 700);
selectClientPopController.delegate=self;
[selectClientPopController presentPopoverFromRect:CGRectMake(cell.frame.origin.x+120-scrollView.contentOffset.x, cell.frame.origin.y+120,cell.frame.size.width, cell.frame.size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight animated:YES];
This navigation view controller is ued to step through a two TableViewControllers as shown below:
When a cell on the last tableView is pressed, I would like to dismiss the whole popover.
I understand that this probably needs to be done using delegates, however I do not know where to assign the delegates in order to achieve this. Thanks for the help.
Why Not
// Listen for TableView row selection by setting up delegate.
// Basically self if you set the delegate in the same view controller
YourTableView.delegate = YourViewControllerObjectWhichHasTableView;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[selectClientPopController dismissPopoverAnimated:YES];
}
Whenever u need to dismiss the popover just use the above method. Refer the Apple's Documentation

Can I change View to the ViewController when click the TableViewCell?

I am new to Objective-C.
It has TableViewCell and the TableView on the ViewController like the following picture.
I want to change the View to another Viewcontroller when I click the TableViewCell.
But it seems can not use the performSegueWithIdentifier to change the View in didSelectRowAtIndexPath without using UINavigationController , The error log like the following:
Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
Is there has another way to change the View to another Viewcontroller when I click on the TableViewCell ?
Thanks in advance.
In Interface Builder(storyboard) click the following:
Exactly what the debugger says: Push segues can only be used when the source controller is managed by an instance of UINavigationController.' Then you'll be able to push segues.
U can present view controller using this
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
yourViewController *vc = [[yourViewController alloc]initWithNibName:#"yourViewController" bundle:[NSBundle mainBundle] ];
[self presentViewController:vc animated:YES completion:nil];
}

Push a new view controller with navigation controller

So I created a new view controller which has the Custom class named DescriptionViewController.
And from my current view controller inside didSelectRowAtIndexPath I use this code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DescriptionViewController *descriptionViewController = [[DescriptionViewController alloc] initWithNibName:#"DescriptionViewController" bundle:nil];
[self.navigationController pushViewController:descriptionViewController animated:YES];
}
But nothing happens when I click on a cell. Is there anything more I need to do ?
If you put in a breakpoint and it is stopping in the didSelectRowAtIndexPath, my guess is that your self.navigationController is nil.
If you are using storyboards, make sure your entry point is a UINavigationController and not a UIViewController.
If you loading this view controller though a modal transition, make sure you push on a navigation controller with this view controller as the root view instead.
Select your viewcontroller in the storyboard and on top go to editor->embed in->navigation controller then instead of initWithNibName try just init

How to open view controller from didSelectRowAtIndexPath within storyboard?

I have a storyboard with tabbarcontroller. One of tab bar has a tableview and I want that when the user tap in a row from tableview open a detail view. The problem is when I open detail view tab bar and navigation bar hides... In the storyboard I create the detail view as a new view controller, then I create a new file and referred it to the class of detail view .
The code in didselectrowatindexpath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
detalleYouTube *dvController = [[detalleYouTube alloc] init];
[self.navigationController pushViewController:dvController animated:YES];
}
Thank you in advance!
This is kinda old but if someone needs to do this here's an easy approach:
You can use add a segue from the view in the tab bar to detalleYouTube, put an identifier to the segue and do this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"segueIdentifier" sender:tableView];
}
Another approach to this is not to use tableView:didSelectRowAtIndexPath but instead use prepareForSegue:sender
the way I did it was:
-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
DetailViewController *viewController = [segue destinationViewController];
CustomObject *custObject = [arrayOfObjects objectAtIndex:[self.tableView indexPathForSelectedRow].row];
viewController.objectNeeded = custObject;
}
This example is based on the idea that your detail view controller is connected to your table view controller.
I presume you have the 'Detail' view as part of the storyboard (not in a separate XIB), if so you will need to place a separate NavigationController at the start of the 'Detail' TabBarItem seque.
This page has a good tutorial on what I think your trying to achieve:
http://maybelost.com/2011/10/tutorial-storyboard-in-xcode-4-2-with-navigation-controller-and-tabbar-controller-part1/
Also check these links to a more in-depth Storyboard tutorial:
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2

Problem In UISplitViewController in iPad

I am working on UISplitView Controller. I have used a SplitView controller template of Xcode. Actually i wanted to implement a scenraio in which when i click on table view cell it should add a New Root Controller with a table View into the Navigation Stack.
i did it using the following code
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NextViewController *nextView = [[NextViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
It works perfect and i have used the RootView Controller code into the NextViewController so that when we click on New Screen's cell it should update my Detail Screen. But unfortuantely it is not updating my Detail Screen.
What can be the reason ??
Please help friends..
Thanks
To updating your Detail Screen. you need to implement a delegate method of communication between Current RootView controller and Detailview controller.
Best Wishes,

Resources