create a menu drop down menu from button in a table view - ios

I have a UITableViewController that is correctly configured and running. let's say the class of this controller is called : tableViewController. On this table, i have a UIBarButton present on the left of the view created like this :
UIBarButtonItem *userProfile = [[UIBarButtonItem alloc] initWithTitle:#"Profile" style:UIBarButtonItemStylePlain target:self action:#selector(userProfileGo:)];
self.navigationItem.leftBarButtonItem = userProfile;
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
I already created another view controller called userProfileViewController, in which the user can access their profile, it is already configured and pushed on userProfileGo this way :
[self performSegueWithIdentifier: #"userProfile" sender: self];
What i want to do , is show up the user profile ViewController when clicked over the tableViewController as a small window
this picture represents my goal :
Is there any possible way to do that ?

I had the same idea in mind, but relating to the low performance it had and iOS users weren't comfortable with it, I started looking for new ideas and I found this library on GitHub
JASidePanels
which looks like this:
This is not related to the answer, but it's just a suggestion I wanted to give to you.
I hope it helps you

You Can use UIPopoverController+iPhone.h for any PopOverView in iPhone also (or) like a dropdown menuView from UIBarButtonItem Ref answer from :UIPopoverController for iphone not working?
also if you need like Sliding Menu means you can use SWRevealViewController Ref : https://github.com/John-Lluch/SWRevealViewController
also you can Refer : https://www.cocoacontrols.com/controls/mlppopupmenu
Also you can call Instance of That menuViewController and add view of that ViewController like [self.View addSubView:menuViewController.View]; by setting the frame with Origin.
Let me know once if it worked or any Queries.

Related

SWRevealViewController project in iOS

Note: Problem solved.
Here comes the story. I am using RevealViewController in my project. I am also hiding the navigationBars:
[self.navigationController setNavigationBarHidden];
My project can be seen in the picture below and the "menuButton" is implemented in the tabBarViewController.
Since the navigationBar is hidden due to my interface looks, all tabViews (HomeViewController) will not show the menuButton and the navigationBar as supposed to. I am not using panGestureRecognizer to trigger the menu aswell.
This means I have a problem to trigger the menu via a normal button in HomeViewController. The menuButton-event is placed in tabBarViewController.m:
_menuButton.target = self.revealViewController;
_menuButton.action = #selector(revealToggle:);
So I tried to call a method from HomeViewController to fire the button in tabBarViewController like this:
HomeViewController.m
- (IBAction) onMenuClicked: (id)sender{
tabBar = [[tabBarViewController alloc] init];
[tabBar setupMenu]:
}
tabBarViewController.m
-(void) setupMenu{
[_realMenuButton sendActionForControlEvents:UIControlEventTouchUpInside];
[_realMenuButton addTarget:self.revealViewController action:#selector(revealToggle:) UIControlEventTouchUpInside];
}
In this example I tried to make the realMenuButton and normal UIButton. Ive also tried as a UIBarButtonItem just to trigger the #selector(revealToggle:) But nothing happens in the app when I try to trigger the button from HomeViewController.
Not sure how I shall make this work. Any other Ideas or tricks? Please be specific if so! Regards
Yes, it will still work.
SWRevealViewController is just a subclass of a UIViewController, so you can use it at any point in the app:
By calling presentViewController:animated at some point.
By using it in a navigation stack etc.
Note that you can add gestures from SWRevealViewController to its content view controllers, which will alter the behaviour of used in a navigation view controller, but that's to be expected, and you still have full control over its behaviour.
Edit
The UI structure of your app is still not clear to me - it looks like you're trying to call revealToggle on an instance of SWRevealViewController when the VC in view is infact HomeViewController? How would this work, when SWVC is not even in view?
My best guess is that your UI structure should be as follows:
TabBarController --->(root)UINavigationController --->(root)SWRevealViewController.
Then, on your SWRevealViewController, set HomeViewController as the front view controller, and the TableViewController as the right or left view controller.
Do you mean like this?
it is possible. you can set the menu button in your tabBarController.m, like this :
UIBarButtonItem *menu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"menu.png"] style:UIBarButtonItemStylePlain target:revealController action:#selector(revealToggle:)];
self.navigationItem.leftBarButtonItem = menu;
self.delegate = self;
For me, my initial view controller is the login screen (obviously I don't need reveal any VC here...). then when user tap the login button,
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:yourRootVC];
LeftMenuViewController *leftMenuVC = [[LeftMenuViewController alloc]init];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:leftMenuVC frontViewController:nav];
revealController.delegate = self;
[self presentViewController:revealController animated:YES completion:nil];
I've tried it and it should work as normal. Even it isn't initial view controller

Switch between ViewControllers using a button?

I am very new to programming, especially iOS, so any answer should be given as if I am a baby with ADHD.
This is what I have in my buttonclick:
ItemCreateViewController *itemCreateViewConrtoller = [[ItemCreateViewController alloc] init];
[[self navigationController] pushViewController:itemCreateViewConrtoller animated:YES];
What am I missing?
There are a lot of reasons why this could be happening among which is your button is not triggering the intended action. Among the reason why a button could not trigger is your XIB button is not connected to the button object defined in your header and method file.
If you look at the .h file look at all your IBOutlet items there should be a circle on the left most column if it is darkened out it is connected other wise it is not, and you need to connect this in your XIB file.
If this is not the problem please display the code where you specify the selector it should be something like this:
[cancel_button addTarget:self action:#selector(Cancel:) forControlEvents:UIControlEventTouchUpInside];
Make sure that the selector is an IBAction function -
-(IBAction)Cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:NULL];
return;
}
One other thing, any statement after pushViewController will get executed prior to any actual change in the view. The actual View change only happens once control is returned to IOS. This is significant if your push view controller command is within a long conditional process and you fail to code the return / exit properly.
Since you are using a XIB file for your second view, you need to create it as follows -
ItemCreateViewController *itemCreateViewConrtoller = [[ItemCreateViewController alloc] initWithNibName:#"ItemCreateViewController" bundle:nil]; //Ensure you use correct nib file name
Then you can push it
[[self navigationController] pushViewController:itemCreateViewConrtoller animated:YES];
But since you are using a Storyboard you could have just added the new view to your storyboard, linked the button to the new view with a "push" segue and everything would have been done for you.

present View Controller on click of Bar Button items

I have included numerous ViewControllers and as per the requirements, all the ViewControllers must contain the two same custom BarButton items(settings,help) in the right and so i created a separate class extending NSObject and included two UIButtons in it.
In all the ViewControllers, i imported this class and set barButtons like this:
NavigationBarButtonItems *nav=[[NavigationBarButtonItems alloc]init];
self.navigationItem.rightBarButtonItems = [nav BarButtonItems];
where, NavigationBarButtonItems is the class containing two custom Buttons in -(NSArray *)BarButtonItems; method.
Everything worked perfect. But Here is the problem, i created a viewController for one of the barButtons, say, 'settings' and i cant figure out how to present this ViewController(settings) when settings barButton is clicked as settings barButton is included in almost all the viewControllers.
Help me out. Thanks!
In the custom class Create the button like this.
-(void)createSettingbutton:(id)FromClass {
//Create Add category Button
UIButton *addSettingButton=[UIButton buttonWithType:UIButtonTypeCustom];
addSettingButton.frame=CGRectMake(0, 0, 30, 30);
[addSettingButton setBackgroundImage:[[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:#"" ofType:#"png"]] forState:UIControlStateNormal];
**[addSettingButton addTarget:FromClass action:#selector(ButtonAction) forControlEvents:UIControlEventTouchUpInside];**
UIBarButtonItem *_addSettingButton=[[UIBarButtonItem alloc]initWithCustomView:addSettingButton];
[self.navigationItem setRightBarButtonItem:_addSettingButton];
[_addSettingButton release];
_addSettingButton=nil;
}
Now add the following code in the viewcontroller where you want to add the setting button.
[self createSettingbutton:self];//Second self is the parameter which is passed to 'FromClass' Variable.
Now in the same viewcontroller add the action for setting button
-(void)ButtonAction
{
[self.view addSubview:mSettingView.view];
//or
[self.navigationController pushViewController:mSettingView animated:YES]
}

Switching views from barbuttonitem? [duplicate]

This question already has an answer here:
Creating nib view from UIBarButtonItem?
(1 answer)
Closed 8 years ago.
So I've seen previous questions similar to this but they were of no help. I've read Apple's documentation too but I could not understand where I've gone wrong. AFAIK I did everything logically, but when I click on my done button on an UItoolbar overlay, the button can be pushed but it does not do anything. This obviously means it fails to acknowledge the written code. But how?
I want to bring up the .nib of "TableViewController" when a done button is clicked on my UIToolBar. But the below isn't allowing the click to bring up a new view. How do I rectify this? Please show me where I went wrong and what should be replaced and why.
//Here's the selector:
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone target:self action:#selector(doneButtonPressed)];
Here's how I made my action. Btw, the uitoolbar has no nib, it's an overlay on the imagepickercontroller(camera mode).
-(void)doneButtonPressed {
TableViewController *tableView = [[TableViewController alloc]
initWithNibName:#"TableViewController" bundle:nil];
tableView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tableView animated:YES];
}
//Yet nothing happens when I click on my done button on my overlay. The button can be
clicked nothing happens. Please shed any insight pleasee!
This may not actually be the problem, but if the code your using above is how you're dismissing your Modal view controller it is incorrect. Other than possible improper usage I don't see any problems.
Use what you're using to present the Modal view controller, then to dismiss it use this:
[self dismissModalViewControllerAnimated:YES];

How to get actions from another UIViewController?

How to get actions from another controller without [self presentModalViewController: ololo animated:YES];?
Can I use just
Tutorial *ololo = [[Tutorial alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:ololo.view];
?
Right now with this code I get EXC BAD ACCESS error, when I'm trying to press button on new view.
May it will be easier to create 2 subclasses of UIView with their own XIBs, or may be I can use NavigateController without navigation bar?
PS Yes, I have Tutorial.h, Tutorial.m, Tutorial.xib. In XIB file there are 2 views (portrait and landscape).
Your question is not clear.
try to pass xibf file name as parameter to initWithNibName,ekse just use int method.hope it wont crash
Make sure that your Tutorial object extends UIViewController
#interface Tutorial : UIViewController {
Also make sure that you have a Tutorial.xib file, which has a view, and the outlet from the view it's linked with the one from the viewcontroller.
as a best practice try this :
Tutorial *ololo = [[[Tutorial alloc] initWithNibName:#"Tutorial" bundle:nil] autorelease];
[self.view addSubview:ololo.view];
Also, if you need 2 views in the same view controller, you can just add 2 views in IB, add an outlet to the second one, and add it as a subview of the main one :
[self.view addSubview:secondView]
this way, both of them are managed by the same viewcontroller, and you can add actions in the same view controller.

Resources