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,
Related
For some reason my navigation controller isn't pushing properly.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"HERE!");
MyViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"myVC"];
vc.labelText = [self.myArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:vc animated:YES];
NSLog(#"Pushed");
}
The output is:
2014-02-17 12:41:47.187 TableViewTesting[37532:70b] HERE!
2014-02-17 12:41:47.189 TableViewTesting[37532:70b] Pushed
So it's all running fine, but I still just see my initial view controller even after tapping on a cell.
Is the view controller from which you are calling this code embedded in the Navigation Controller? If it's not, then nothing would happen when you call pushViewController method.
Go to your Storyboard, select the initial view controller, then from the top bar Editor > Embed in > Navigation Controller and try again.
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
I'm trying to build my iOS app's interface. Starting over and over with new project i'm still getting a problem with a detail view's controls (see picture).
Here i got the screenshots:
detail view shows when user touch to the UITableView row. You can see the difference between my design and final result on the simulator screen - this is the problem
main xib design
this is how i open the detail view:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
autolayout - that is the source of bugs in my design. I just switched it off on the detail xib and now all controls are in its right places
thank you Rob
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
I am creating an app that uses a navigation controller.
In the the first view I have three different table views.
How can I make the tables open a new view in the navigation controller when one cell is selected?
Thanks
You implement tableView:didSelectRowAtIndexPath: as a delegate method on the view controller that shows the three table views, and in this method you initialize the new view controller you want to show and push it onto the screen by doing something like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// TODO: Find out what view controller to push based on the tableView and the indexPath.
UIViewController *viewController = [[YourSpecialViewController alloc] initWithNibName:nil bundle:nil];
[[self navigationController] pushViewController:viewController animated:YES];
[viewController release];
}