MMDrawerController with StoryBoard Menu Item - ios

I'm using MMdrawerController to practice side drawer controllers in my project. But when I tap on the menu button on the left side, then tap to the row that selected, it opens just fine, but the corresponding view doesn't show menu item (drawer menu button) on the left of the view. So I can't make any further selection.
And I use storyboard.
Sample code from MydrawerController
I navigate through cells in drawer's tableview.
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.delegate drawerMenuViewController:self didSelectMenuSection:indexPath.row];
switch ((MMDrawerMenuViewControllerSection)indexPath.row) {
case MMDrawerMenuViewControllerSectionProfile:
[self.mm_drawerController setCenterViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"MMProfileViewController"] withCloseAnimation:YES completion:nil];
break;
default:
break;
}
}
My center view is simply does these:
-(void)setupLeftMenuButton{
MMDrawerBarButtonItem *leftDrawerButton=[[MMDrawerBarButtonItem alloc]initWithTarget:self action:#selector(leftDrawerButtonPress:)];
[self.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)leftDrawerButtonPress:(id)sender{
[self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}
-(void)doubleTap:(UITapGestureRecognizer*)gesture{
[self.mm_drawerController bouncePreviewForDrawerSide:MMDrawerSideLeft completion:nil];
}
And my other view controller that can't display menu item has the same button handlers given above. But still not showing the menu item.

It's not possible to push the controller into centerView from the side view, I have done this but need to use the delegate, I have define a protocol into left side controller like
#protocol LGSettingDrawerControllerDelegate <NSObject>
- (void)pushControllerWithIndex:(NSIndexPath*)indexPath;
#end
#property (nonatomic, weak) id<LGSettingDrawerControllerDelegate> delegate;
and in
in
.m file
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (_delegate != nil) {
[_delegate pushControllerWithIndex:indexPath];
}
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}
and this delegate method do push at center view controller like
[self.mm_drawerController setCenterViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"MMProfileViewController"] withCloseAnimation:YES completion:nil];

Related

Dimissing TableViewController unwinds to first storyboard

I have a UITableViewController embedded in a UINavigationController.
When I click a button in my Detail View (Detail view is in a UITabViewController) to showList the UITableViewController (List Table View) called List is presented.
If I click the Back button in the navigation controller, I am taken back the correct screen: Detail View Shown by the Blue Line
If I select an list item the delegate method didSelectFromList is called from the didSelectRowAtIndexPath and the app is taken back to main screen (Home View) shown by
the red line.
What I want is the purple line.
Any help?
Attempt 1:
I let the delegate dismiss the List TableVC.
#import "ListTableViewController.h"
#interface CallDetailViewController () <ListTableViewControllerDelegate>
#property (nonatomic, strong) LotListTableViewController * lltvc;
#end
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"segue_list"]) {
self.lltvc = (ListTableViewController*)segue.destinationViewController;
self.lltvc.delegate = self;
}
}
- (void) showList {
[self performSegueWithIdentifier:#"segue_list" sender:self];
}
#pragma mark LIST SELECTION DELEGATE METHOD
- (void) didSelectFromList:(NSString *)item {
[self.lltvc dismissViewControllerAnimated:YES completion:^{
NSLog(#"Did Select item: %#", item);
}];
}
In the LIST TABLE VIEW CONTROLLER
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
///.. stuff to find the correct string
[self.delegate didSelectFromList:item];
}
Attempt 2:
Here I let the List TableVC dimiss itself.
#import "ListTableViewController.h"
#interface CallDetailViewController () <ListTableViewControllerDelegate>
#end
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"segue_lots"]) {
NSLog(#"GOING TO THE LOT LIST");
UINavigationController * nvc = (UINavigationController*)segue.destinationViewController;
LotListTableViewController *lltvc = [nvc childViewControllers][0];
lltvc.delegate = self;
}
}
- (void) showLotList {
[self performSegueWithIdentifier:#"segue_lots" sender:self];
}
#pragma mark LIST SELECTION DELEGATE METHOD
- (void) didSelectFromList:(NSString *)item {
NSLog(#"Did Select item: %#", item);
}
In the LIST TABLE VIEW CONTROLLER
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
///.. stuff to find the correct string
[self dismissViewControllerAnimated:YES completion:^{
[self.delegate didSelectFromList:item];
}];
}
I have also tried from the didSelectRowAtIndexPath in the List TableVC
[self.navigationController dismissViewControllerAnimated:YES completion:^{
[self.delegate didSelectFromList:item];
}];
If you keep on pushing view controller, they get added to the navigation stack, so if you do [self dismiss or [self.navigationController dismiss, all the navigation stack is cleared and you will betaken to the rootViewController.
Either you can pop one view controller or
Instead of pushing the navigation controller from detailVC, present the navigation controller that has the list table VC. In that case [self.nav dismissviewCOntroller will work,

Navigation bar is showing in storyboard but not simulator

The following is my storyboard ,
and the ViewController(CaseInfo or VC2) is showing the navigation bar
http://i.imgur.com/nQqj1IQ.png
but in my simulator the navigation bar dosen't show up !
In VC1(CaseList):
I make the VC1 be the rootView of the navigation controller
and I link the VC1 to VC2 with choosing "push" option
then I use the code when I click the table item of VC1:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CaseList *tagEditor = [self.storyboard instantiateViewControllerWithIdentifier:#"CaseInfo"];
[self presentViewController:tagEditor animated:YES completion:nil];
}
But the Navigation bar in VC2 doesn't show up
Please Help Me...
Thank you!!
-
btw
I also use the code in VC2(CaseInfo)
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
In your code,since you have linked the VC2 and VC1 with a segue
you just need to fire it
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self performSegueWithIdentifier:#"segueid" sender:nil];
}
Then in prepareForSegue,pass some data.
Or
You can delete the segue between VC2 and VC1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CaseList *tagEditor = [self.storyboard instantiateViewControllerWithIdentifier:#"CaseInfo"];
[self.navigationController pushViewController:tagEditor animated:true];
}

iOS Access parent view elements from child view

I have a ViewController1.h/m and SettingsViewController.h/m. In ViewController1.m I have this:
ViewController1.h
#property (nonatomic, weak) UIView *settingsView;
ViewController1.m
//alloc init _settingsView
SVC = [[SettingsViewController alloc]init];
[self addChildViewController:SVC];
SVC.view.frame = self.view.bounds;
[_settingsView addSubview:SVC.view];
[SVC didMoveToParentViewController:self];
I don't remove ViewController1 from parent view when I add the settings. It's just off to the side and slides in when I'm toggling the settings view with a button. Inside SettingsViewController I have a table and on a row click I want to slide the SettingsViewController back off the screen and perform a selector from ViewController1...that's where my problem is right now. Here's what I try to do:
SettingsViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 0) {
ViewController1 *VC1 = [[ViewController1 alloc]init];
[VC1.settingsView setFrame:CGRectMake(320, 0, VC1.view.frame.size.width, VC1.view.frame.size.height)];
//NSLog(#"%f", VC1.settingsView.center.x);
//tried:
//[VC1 performSelector:#selector(...)]; I have the method declared in VC1.h
}
}
Logging the VC1.settingsView.center.x always gives me 0...when it should be 160. Adding a log statement in VC1 methods when running performSelector DOES log but the rest of the method doesn't run, doesn't slide the SettingsViewController off the screen. Am I not understanding parent/child relationship???
Crap, found the answer after hours of trying...thanks to this
if([self.parentViewController isKindOfClass:[SomeViewController class]]) {
SomeViewController* viewController = (SomeViewController*)self.parentViewController;
[viewController foo];
}

Flip Transition from a Tableview Custom Cell to a UIViewController

I created a custom tableview cell that gets displayed in my tableview. Upon user tapping the cell, I would like to create a flip horizontal transition to a new view controller. How to do this either using Core Animation or UIView?
Sorry I am a newbie can't find the right way to do it anywhere.
Thank you in advance.
I guess You are talking about this.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create the next view controller.
DetailViewController *detail= [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
[detail setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:detail animated:YES completion:nil];
}
For Dismiss:
-(IBAction)close:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
write this method in DetailViewController and call this method to back.

How to present modal view in "parentViewController"?

I'm trying to write iPad app.
I have UIViewController as parentViewController (full screen) for masterView and detailView (my handmade splitView). Also I have a separate view (for example moreDetailView) with class and xib, which I would like to show as modal.
masterView has UITableView and detailView has UICollectionView. Both of them has own classes and xib. In detailView there are several items.
In my didSelectItemAtIndexPath: of detailView I would like to show moreDetailView.
So, how can I do that? And how to show it in parentViewController, but NOT in detailView.
Hope my question is understandable.
The code below will present your controller in a modal formsheet (you can change this with the setModalPresentationStyle) on the top of your splitView.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
[moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
[moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:moreDetailViewController animated:YES completion:^{
//stuff you want to do after the viewController has been presented
}]; }
You are initializing your masterview and detailview in parentview. To access the parentcontroller you can declare a property in detailcontroller as
UIViewController *parent;
and while initializing you can do
detailController.parent=self;
and while showing modal you can do
[parent presentModal]; //instead of [self presentModal];
I hope above works for you, you will need to correct the syntax though.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
[moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
[moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:moreDetailViewController animated:YES completion:^{
//stuff you want to do after the viewController has been presented
}];
}

Resources