Bar Button Item : IBAction not fired in View COntroller - objective-c

At the bottom of the Detail View Controller of a Split View Controller, I have added a Toolbar in the Storyboard. I have added three Bar Button Items in this Toolbar. Each Bar Button Item is hooked to its IBOutlet in the private interface of the Details View Controller, and also hooked to its IBAction implementation in the same controller, for example:- (IBAction)shouldPresentView:(UIBarButtonItem *)sender
The main view contains:
A Webview.
A small rectancgle view at the bottom of the screen, below the webview, created and added programmatically, and containing various buttons. All the buttons stay operational.
When touching any of the Bar Button Items, the button is temporary highlighted, but none of the IBAction methods is triggered (a NSLog() statement in every method is never executed).
After searching and reading equivalent topics, I went through several solutions:
I added manually the Details View Controller as the delegate of the Toolbar in the View Did Load method of the Details View Controller.
I emptied the cache of the Derived Data of the Product.
I checked that every IBOutlet has an address and is not nil.
I tried to add an action SEL manually in the View Did Load method for every Bar Button Item.
I removed the rectangle bottom view to be sure that it was not interfering with the responder chain.
I added a Bar Button Item in the Navigation Bar to check if the same problem occurs: no, the Bar Button Item fires the IBAction method.
Any help would be appreciated.
Developing with iOS 7 SDK in Xcode 5.0.2

The issue was coming from a Tap Gesture that I added to the main view to collect touches on the web view. So the touch on the Bar Button Items was probably captured somewhere by the main view before reaching the UIButtonBarItem. I changed the target of the Tap Gesture to the web view – more logical – and the issue has been solved.

Related

Tab Button Begins Editing Wrong Text Field

I have a UIViewController, VC with some elements on it, 2 of which are UITextFields. There is a button that, upon the users touch, presents a new controller CustomAlertViewController, VCAlert over the current VC with a modal presentation style of UIModalPresentationOverCurrentContext.
In this VCAlert I have 3 text fields.
When I press the tab key on my bluetooth keyboard, initially it only toggles through the 2 text fields on VC, even after presenting VCAlert, which is now the top-most presented view controller.
This is the important bit:
AFTER I tap one of the 3 fields on VCAlert, pressing the
tab button correctly toggles through the 3 fields on the top-most view
controller, now ignoring the input fields in the view controller underneath.
Is there a way to tell VCAlert (the top-most presented view controller) to listen for the tab button events, and NOT the parent controller any longer (until of course VCAlert is dismissed)?
I would like to accomplish this without having to remove the delegates from the 2 VC text fields, OR removing them from the view.
CODE:
The code is extremely straightforward... so it will be limited.
Each UITextView has its delegate registered to the respective view controller. The VCAlert controller is presented in the following way:
// Here, self is the VC, and alertViewController is VCAlert
[self presentViewController:alertViewController animated:NO completion:^{
// Do absolutely nothing here like usual
}];
FYI:
I have tried called becomeFirstResponder on one of the text fields in VCAlert then immediately called resignFirstResponder, but it doesn't make the tab bar toggle them - it still toggles the fields on the view controller below.

Adding button which should be visible in all view controllers

How can I make a button or any view which should be visible in all the view controllers and its action can be called from all the view controllers? Popping and pushing of viewcontrollers should take place behind that button. I don't have any code but I have a reference app, Moise Bently, in this app it has a button on top right corner.
Try adding _yourView/button to your window... you can do this in didFinishLaunchingWithOptions also you can do [self.window bringSubviewToFront:_yourView] when required.. if you add some other view over it.

Tab Bar controller disappearing when moving to another view (iOS SDK, Using storyboards)

I am building an iPhone app using storyboards and I have a problem with the tab bar controller. On one of the views that is linked from the tab bar controller (view1), there is a button that leads to another view (view2). On View2, there is a button that leads back to View1. Very straight forward. But when I go from view1 to view2, the tab bar disappears, and even worse, when I go back to View1, the tab bar is still gone...
How can I fix that? (I have yet to put ANY code in the app, there is only the storyboard and the apple provided AppDelegate Class (and also a main file I suppose, but I am not intending on touching that).
Any Reply is Highly appreciated!
If you do a modal segue from a view that is a tab bar view, it will get rid of the tab bar for the modal view you are presenting.
Secondly, when you segue you are creating a new instance of the view controller. So I am guessing you are segueing from view1 to view2 and losing the tab bar, then you are segueing back to view1. At this point you have created view1, view2, and a second copy of view1 that does not have a tab bar.
I would suggest one of two things.
1.) If you want to keep the tabs at the bottom when you segue from view1 to view2, then click on view1, at the top of the screen select Editor/Embed In/ Navigation Controller. This will embed your view1 in a navigation controller. Then if you change your segue from Modal to Push it will keep your tab bars at the bottom. The navigation bar at the top also make it easy to go back from view 2 to view 1 the correct way (by popping the view) rather than creating a new segue. If you do not like the navigation bar, then you can change the "Top Bar" property to "None" in the inspector. You will then need to create some other way in view2 to get back to view1. (BY POPPING THE CONTROLLER, NOT BY SEGUEING)
2) If you don't want to set up a navigation controller you will have a little bit harder time keeping the tab bar stuff at the bottom of the view2 controller. In fact, I'm not sure you can do it at all with a modal segue, you'd probably have to write some type of custom segue. Either way, If you want to transition back to view1 and get to the correct controller (not a new version without the tabs) then you need to attach an action to whatever button you are using to segue and use the following code (I also attached the code for navigation controller push segues, in case you create a navigation controller and get rid of the navigation bar.)
For Modal Segue:
[self dismissModalViewControllerAnimated:YES];
For Push segue:
[self.navigationController popViewControllerAnimated:YES];
Your best bet is to use the navigation controller method, as you are assured to keep your tabs. You can then either use the navigation bar to return (the easy way, no code needed) or you can get rid of it and use a button and the code above.
Good luck!
I had the same problem, i know this is an old question but [self dismissModalViewControllerAnimated:YES]; is deprecated in iOS 6.
What i used is:
[self dismissViewControllerAnimated:YES completion:nil];

How to access Navigation Bar from a View Controller of a subview ?

I have a View Controller where I select some data into an array and then optionally on clicking of a button I show that data in a TableView added as a subview to previous view with a flip animation.
Now I have the facility to delete data from array I have picked from first view and passed to this one.
Now I have a condition that there is a button on the righthand side on the navigationBar on whose controller the previous view was pushed.
Now that button needs to be disabled until there r atleast X number of elements in the array.
so while I am adding data In my previous view, I keep check on the array and as soon it crosses the required count , I enable the button.
Now in the other view which is a TableView which has been brought in with animation,
Whenever I delete data I need to disable the button again when it goes below the number X.
How can I access the navigationBar's button in this subview's controller ?
shall I set the first view Controller as delegate in the next one ?
If your viewController is inside UINavigationViewController, you can set navigationBar buttons with self.navigationItem.leftBarButtonItem and self.navigationItem.rightBarButtonItem.
try using superView proprty or loop through all the pushed ViewController and check if it is previous VC. Then make the button enabled or disabled
My opinion is you can create a uinavigationController object in your subview and assign it from your parent view(Where you have the navigation controller object). You can then access the navigation controller in the subview.

Setting Toolbar Items of UINavigationController

In iPhone OS 3.0, you can set the toolbar items of a UINavigationController using the setToolbarItems:animated: method. However, this requires you pass in an array of UIToolbarItems. While I could programmatically create these toolbar items, I'd rather create them in Interface Builder if possible.
With this in mind, I have created a UIToolbar in "MyGreatViewController.xib" and have populated it with the wanted toolbar items. Then, in "MyGreatViewController.m", I get the items from the toolbar and pass them to setToolbarItems:animated::
- (void)viewDidLoad {
[super viewDidLoad];
[self setToolbarItems: [toolbar items]];
}
...where toolbar is an IBOutlet referring to the UIToolbar.
Is this a good approach? Is there a better way to accomplish this? Should I just create the items programmatically?
I don't know if this is documented anywhere, but I've found that in Interface Builder, if you enable the navigation controller's toolbar, you can drag bar items to your view controller, and they will automagically show up in the navigation controller's toolbar.
For example, here's what we can do (using Xcode 3.2 on Snow Leopard):
File->New Project.... Choose Navigation-based Application and create the project.
Open MainWindow.xib in Interface Builder.
Select the Navigation Controller, and in the Attributes inspector, check the "Shows Toolbar" box. This will cause a Toolbar object to appear.
Drag a Bar Button Item from the Library to the toolbar. It will appear in the toolbar. If you check the hierarchy in the NIB, you'll see that this new item is a child of the RootViewController.
It seems that any Bar Button Items added as children of the navigation item will show up in the navigation bar, and any Bar Button Items added as children of the view controller will show up in the toolbar.
(I stumbled on this by accident. If anyone can find documentation for this behavior, or any additional info, I'd like to hear about it.)
It's a perfectly acceptable way of doing it, but do bear in mind that loading xib files is quite expensive on the iPhone, and it may well be faster to create the toolbar items programatically in your viewDidLoad method.