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];
Related
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
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.
I have some problem in my application.
In my application there is a possibility to edit some information (something like iPhone's contacts). When you press 'Edit' button on right of navigation bar, "Back" button should hide, and "Cancel" button appear.
It working perfectly, when user press "Edit" button straight from ViewController.
But, when user creating a new advert, the view controller with editing should open, in edit mode. I call it this way:
VICarInfo * vc = [[VICarInfo alloc] init];
[vc setCurrentAdv:adv];
[self.navigationController pushViewController:vc animated:YES];
if (editMode) {
[self.navigationItem setHidesBackButton:YES animated:NO];
[vc btnEditClick];
}
And "Back" button didn't disappear.
I also tried to hide button in ViewWillAppear, ViewDidLoad or ViedDidLayout subviews, also unsuccessful.
Please, give me any advices, how to do it.
Thank you.
Use this :
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];
I know this is late, but I was seeing the same thing and found a solution.
It seems that hidesBackButton = YES interferes with setting the leftBarButtonItem(s).
Don't use hidesBackButton and you'll lose the overlay.
This seems like a bug, but Apple's own documentation is pretty hazy on the interaction of those two/three properties.
Try this one..
[self.navigationItem setLeftBarButtonItem:nil];
[self.navigationItem setHidesBackButton:YES];
Since iOS 5.0:
self.navigationItem.leftItemsSupplementBackButton = ?;
NO - having leftBarButtonItems hides the backButtonItem (default),
YES - leftBarButtonItems co-exist with the backButtonItem
There still seems to be an iOS 7 bug however, that hides (or not) the backButtonItem indiscriminately.
try on real device . showing custom image on real device . But not ios simulator . if you do test on simulator , you will see ios default back button .
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.
-(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, but nothing happens. Please shed any insight pleasee!
Did you create the UIToolbar into a nib file?
I am making an application that has a UITabBar and it works just fine, however I want to add a first screen which contains some instructions and a logo, then a button and when said button is pressed to show the UITabBar I've tried for a couple of days to do this on my own with no luck, I'm not even sure if it can be done, could anyone help me out? or give me a lead?
Try setting up the tab bar application, and then showing the first screen over it as a modalViewController. Inside your main app's viewController:
FirstViewController *firstViewController = [FirstViewController alloc] initWithNibName:#"FirstView" bundle:nil];
[self presentModalViewController:firstViewController animated:NO];
[firstViewController release];
When the button is pressed inside the modal view, call:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
to get rid of it. You can adjust the animation style for the dismissal, or use NO instead to have it just disappear.