slide out menu move to another view controller - objective-c

I followed this great tutorial on a slide out menu using UIKit Dynamics, Slide Out Menu. The code has been slightly modified to reduce duplication of code. I'm handling the touch event in the MenuComponent Class. Now, I'm trying to move to another view controller when the item is selected. The menu is created in code so I can't use segue's.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO];
[self toggleMenu];
self.isMenuShown = NO;
if(indexPath.row == 0){
//move to the testViewController
}
How do you remove the current view and present a new one? My hierarchy is a navigation controller then my testViewController.
Edit: I did find this code which I tried, but my problem is the when the menu is present and I try to present the view I get an error:
testViewController *test = (testViewController*)[storyboard instantiateViewControllerWithIdentifier:#"testViewController"];
[self presentViewController:test animated:YES completion:nil];
Warning: Attempt to present <testViewController: 0x7c095470> on <MenuComponent: 0x7ae4ce50> whose view is not in the window hierarchy!

I was able to figure it out by creating a delegate for the MenuComponent and then pass the view like so:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * test = [storyboard instantiateViewControllerWithIdentifier:#"test"] ;
[delegate didCallViewController:test];

Related

View gets pushed down when performing segue with a visible navigation bar

I'm performing a segue with a navigation bar over a view that has the navigation bar hidden, when the segue starts my current view seems to get pushed down by the navigation bar that is not hidden in my segue… which looks bad…
If I remove the setNavigationBarHidden:animated method I don't see a navigation bar after performing the segue, and the issue doesn't manifest anymore.
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
if (indexPath.row == 0) {
[self performSegueWithIdentifier:#"mailSignUp" sender:nil];
} else if (indexPath.row == 1) {
[self performSegueWithIdentifier:#"logIn" sender:nil];
}
}
If you want to hide your navigation bar you have to do it in the root controller, the first controller in your app.
My guess is that you have had setup a modal segue in interface builder from a certain button to the following view. By doing so you have the following view sliding in from down to top.
I'm also guessing you are using the lastest xcode version [4.5.2] and running it on ios6.
Try deleting your segue from interface builder. Also, instead of your:
[self performSegueWithIdentifier:#"mailSignUp" sender:nil];
use:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
YourSecondController *secondController = (YourSecondController *)[storyBoard instantiateViewControllerWithIdentifier:#"YourSecondController"];
[self.navigationController pushViewController:yourSecondController animated:YES];
[substitue YourSecondController with mailSignUp or whatever controller you want to perform segue to]
Also, if you want to hide your navigation bar you have to add this line of code in your (void)viewdidload method in your root controller.
If you run your segue programmatically like this, you should achieve your second view slide from right to left. Let me know if this helped or provide more info if it is not sufficient or exact.

NewView showing in PopOver instead of newView

I have the right view selected from my PopOver but instead of showing in Parent View it is showing in PopOverView.
Here are some screenshots:
After I select the Feedback option instead showing the view in my parentview which in my case is SecondViewController (grey background screen) it is showing in the PopOver itself.
For information I have Three VC's namely FirstViewController, SecondViewController and ThirdViewController each assigned to each TabBar item. I want to make SecondViewController as parent for the PopOver.
Here is my code where I create PopOver in my AppDelegate.m
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([viewController isKindOfClass:[SecondViewController class]]){
NSInteger index = [[self tabBarController] selectedIndex];
CGRect buttonFrame = [[[[[self tabBarController] tabBar] subviews] objectAtIndex:index+1] frame];
PopOverViewController *popoverContentController = [[PopOverViewController alloc]init];
UINavigationController *navcon = [[UINavigationController alloc]initWithRootViewController:popoverContentController];
popoverContentController.contentSizeForViewInPopover = CGSizeMake(250, 85);
popover = [[UIPopoverController alloc]initWithContentViewController:navcon];
NSLog(#"X:%f Y:%f",buttonFrame.origin.x,buttonFrame.origin.y);
[popover presentPopoverFromRect:buttonFrame inView:self.tabBarController.tabBar permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
And the code in my PopOverController.m where I am making a choice of which new view to show
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
sendFeedback *sendEmailViewController = [[sendFeedback alloc]initWithNibName:#"sendFeedback" bundle:nil];
downLoad *downloadFilelViewController = [[downLoad alloc]initWithNibName:#"downLoad" bundle:nil];
if (indexPath.row == 0)
[self.navigationController pushViewController:sendEmailViewController animated:YES];
else
[self.navigationController pushViewController:downloadFilelViewController animated:YES];
}
Can anyone let me know how I can make the reference to my parent view (SecondViewcontroller) so that the new view shows in my parent view rather than the popover view.
Thanks
You insert into popover UINavigationController and in didSelectRowAtIndexPath push newly created controller to existed stack (into popover UINavigationController), but not into tab bar.
In order to push newly created controller to second tab you need to assign second tab (now it is SecondViewController) to new UINavigationController and use exactly this navigation stack.
Code will look like this:
UINavigationController *navController = (UINavigationController*)[tabBarController.viewControllers objectAtIndex:1];
[navController pushViewController:downloadFilelViewController animated:YES];

unable to create a back button when navigate from a table view to another

this is a newbie question.i ve created a grouped tableview .on clicking the tableview cell it navigates to a new view.but i m unable to create a back button.I even added a navigation bar in the second view of the nib file.but its of no effect..could you guys help me out..below is the screenshot and code of the first view
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
if (indexPath.row==0) {
self.dvController1 = [[FirstView alloc] initWithNibName:#"FirstView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController1 animated:YES];
}
if (indexPath.row==1) {
self.dvController2 = [[Tab4 alloc] initWithNibName:#"Tab4" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController2 animated:YES];
}
}
In the presented controller add a button with an IBAction in it:
- (IBAction)back:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
And make sure that you have a navigationController indeed (meaning that your application needs to be navigation oriented, meaning that you need to instantiate the navigationController property in the application delegate)
In your second view .put this code in viewDidLoad method
self.navigationItem.leftBarButtonItem.title = #"Back";
just hide the bar in the viewWillAppear method & unhide the bar in viewWillDisAppear methods of the tableViewController class. By using
self.navigationController.navigationBarHidden = YES/NO;

How to load a table from a .nib when an item in a previous table is selected?

At the moment, I have an iOS app that starts out with a NavigationView (root view) and a table contained in the root view below the navigation bar. I am attempting to load another view (hoping to make it another table) from a .nib file when the first row in the original table is selected. How can I do this?
Any help or advice would be appreciated. Thank you very much.
You need to make use of the UITableViewDelegate method, tableView:didSelectRowAtIndexPath:
Ensure that your tableview's delegate is set to your view controller inside Interface Builder, or if you are not using interface builder..
[tableView setDelegate:self];
Your view controller will then adopt the UITableViewDelegate protocol and respond to tableView:didSelectRowAtIndexPath: when a row is selected.
Loading your new view when the first row is selected will be implemented like so..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0){ // the first row
MyView *myView = [[MyView alloc] init];
[self.navigationController pushViewController:myView animated:YES];
[myView release];
}
}

Accessing UITableViewController > UIView > UIView?

Can anyone tell me if this is possible?
I have a setup a UITableViewController which consists of a number of cells, if you select one of these cells you are taken to a new viewController using pushViewController (see below)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSLog(#"CELL__: You tapped the row ... %#", [list objectAtIndex:row]);
TestController *testController = [[TestController alloc] init];
[[self navigationController] pushViewController:testController animated:YES];
[testController release];
}
If in the implementation for "TestController" I would like to refer back to [self navigationController] (or maybe to add yet another view) is there any way to do that. My problem is that I need to access [self navigationController] to push further views and I don't know how to do that from the bottom controller?
Does that make sense?
Gary
From within TestController you reference the same UINavigationController via [self navigationController] as well.
EDIT to elaborate after comment:
The navigationController property is a property of UIViewController. If the controller is contained within a UINavigationController then it's own navigationController property will be a reference to that container UINavigationController. The same applies for tabBarController and splitViewController.