iphone app button method not being called - objective-c

I have a button in an app labelled "How to search", the referencing outlet is "btnHelpShow" and it has the method "handleHelpShowButton" attached to the "Touch up inside" event.
The app is a simple search engine to find prices for number plates:
This is the SearchView.xib file's hierarchy in Interface Builder
The view be in 4 states:
1) Waiting to search (pictured)
2) Showing help screen
3) Results found
4) No results found
State 2 and 4 create a view with a seperate .xib file and insert it onto the view stack, they then both have a button that hides the view and shows the search screen again.
State 3 is a sub-view inside SearchView.xib (pictured), as in I've just used interface builder to drag that view into the .xib. So it just gets it's hidden property set to YES/NO
After State 3 occurs, the "How to search" button stops working, and will only work again if you select the input field and type in another number plate.
I've used NSLog(#"pressed") as the first line of the handleHelpShowButton, and that doesn't get logged after State3, it's like the button's been disabled or there is an invisible view sitting over it stopping me from pressing it.
I'm not sure where to look from here? There's a lot of code so I don't want to post it all in one go.

Perhaps the subview that is created for state three overlaps the 'How To Search' button? Check the frame for that subview in an NSLog.
If this is indeed the reason, you could try:
[self.view bringSubviewToFront:howToSearchButton];
You can learn more reading the UIView documentation.

Related

Load Second UIViewController into Container on Button Click

So here is my situation, I have a few UIViewController's, they are:
View Controller
First Sector
Second Sector
The View Controller (1) has buttons on the left (within a UIView) and it has a UIContainerView which slides to the right (to reveal said buttons) with a gesture - this is hopefully going to be my menu (see screenshot).
The First Sector (2) I have managed to load as the default view of the ContainerView mentioned above.
I want to load the Second Sector (3) into the ContainerView when the button is clicked.
Screenshot so far:
How is it I am going to get this to load into the container?
I have tried to drag the "embed" from Presenting Segues across to the Container, however that just gives the option of viewDidLoad which obviously sets it as default.
There is a library that already implemented all work for you. It's called SWRevealViewController. It's a really powerful library to present menu on the left like you want to.

View Controllers, Popup buttons, AppDelegates, Status Menus, and headaches

This is kinda long but I want to give as many details as possible.
I have created a status bar app. One of the things I've done is made it to where there is a "Settings" menu item that if you click on, an NSWindow pops up with 5 different buttons -- these buttons are tied to their own custom NSViewController so that if you click them, the View Controller changes, but the window remains the same, just like any other StatusBar app.
On one of the view controllers is a popup button with several user selectable options. If I add a button to the specific VC (view controller) and link that to an ibaction that pulls the selected index of the popup button, it works just fine (i.e. I select item 2, it logs item 2).
Now here's where things get. . . odd. I've created a submenu that would in theory allow the user to quickly change the selected item of the popup linked to my custom view controller. Think of this submenu as being labeled 1-4 and clicking one of those items would change the index of the popup button, however every time I try this and follow it up with a NSLog to ensure the button has changed, it ALWAYS reads zero, in other words, it NEVER changes.
Here's what I tried.
Just like with every other view controller I've ever used, I create a new object of my view controller (alloc, init), and reference the popup button object that i've created as a property. This compiles just fine, but returns only zero no matter what is selected.
I've tried calling the method that I know works (the button that is on the view controller containing the popup), but again, this returns only zero no matter what is selected.
Any advice would be greatly appreciated.
tl;dr: can't change a popupbutton on a view controller from the app delegate or nsstatusmenu item, it just always returns zero.
EDIT: I have found a work around since I can communicate to my app delegate just fine, I created an int property and set it to zero. From there, whenever my popupbutton on my VC changes, I change the value of the app delegate int property and just ensure that whenever the nib launches, it set's the selected item to the app delegate property. I feel there has to be a more straight forward way to just get the value of the popup and change it from the app delegate.
EDIT 2: Some code as requested. I realized I needed to point the the view controller by using initwithnibname from the app delegate and then load the view. Doing so allows me to pull the first object in the popup button, any subsequent changes are not recognized unless I do so via my test button on the view controller itself. Also, I'm adding values to my popup in my awakefromnib in the view controller.
searches_VC = [[Searches_ViewController alloc] initWithNibName:#"Searches_ViewController" bundle:nil];
[searches_VC loadView];
NSLog(#"Selected Title: %#",[[searches_VC profilePopupOutlet] titleOfSelectedItem]);

How Can I Change UIImages in a ScrollView based on a User's Input

Okay gang, I'm scratching my head on how to accomplish this one so I wanted to put it out to the world at large.
Essentially what a client wants is a way to toggle PART of a view based on whether the user selects a "Yes" or "No" option. My question is how would I go about accomplishing that?
Allow me to provide some more details. Within this specific app resides a form (a form with custom text fields, picker views, switches, sliders and other UI elements) that have all been laid out in a Storyboard, then programmed to function. About 3/4 of the way down this form, the user will be greeted with a "Yes" or "No" option and a button for each. The trick is that each view needs to have its own UI elements (text fields, sliders and buttons) appear ONLY when one of the options is selected and only BELOW the "Yes" or "No" option (all the elements above it need to remain, stay in the same place and hold the information the user enters).
An example : If the user hits the "Yes" button, below it 3 lines of text followed by a UIButton and Text Field would appear. Underneath this, other navigation buttons which navigate to other ViewControllers would appear. However, if the user hits the "No" button , all of those items I mentioned a moment ago would need to disappear, and instead a different set of text fields, labels, buttons and background image would need to appear. The navigation buttons will also need to link to other ViewControllers, different from the buttons in the "Yes" option. At this point I suggested to the client that a Navigation controller rooted at the bottom of the screen would be a good idea, but they are vehemently opposed to this and instead want the navigation options to be "dynamic" (or change according to which option is pressed, "Yes" or "No").
I have thought to attempt this programatically by simply using each button to load in a different image, this works just fine. The hitch then becomes twofold;
1) When I attempt to load the other UI elements that I get no way to lay them out in a storyboard and thus they appear in sporadic locations and
2) All this needs to be contained within a scroll view, which ALSO needs to change its size depending on how much space is needed below the yes and no option. Naturally the "Yes" section is 3 times smaller than the "No" section.
So, any ideas on how to make all this happen? I should mention at this point that the client also does not wish to simply navigate to a different ViewController, they very much want all this to occur on the same screen. I wish I had some code to share but we are still in the "design" aspect of this project and as such, very little code has been written. Any advice will be much appreciated as I've never been greeted with this type of build request before.
Create a UINavigationController object and set your view(say yourViewController) where your Yes and No buttons exist as a root view controller as below
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:yourViewController];
Now when user press YES/NO button on yourViewController view than you can programmatically create all controls text field and buttons and set frame according to your view. like
UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(enter frame accordinglly)];
[self.view addSubview:txtField];
same you can add more controls like buttons or any other controls.
after that when user press any the button(on which you want another view to display) you can push other view in the navController as below
[navController pushViewController:otherViewController animated:YES];
you need to keep track of navController in your yourViewController
when you want to go back just pop view from navController
[navController popViewControllerAnimated:YES];
PS: please be watchful for memory deallocation as well.

Apple Sample Code : Multiple Detail Views

I just downloaded the apple same code Multiple Detail Views.
http://developer.apple.com/library/ios/#samplecode/MultipleDetailViews/Introduction/Intro.html
I was playing around with it to try and figure out how it works, and so far I have only had one problem: when I create my own files/view, there Menu button is not present.
Default first view controller with Menu button
The drop down menu with the third view that I created
The third view that I created, that has no menu button
I poked around the interface builder and there are no buttons there for the default views. Then I found a method in the RootViewController that displays the button.
My problem is that I can't find where the first 2 views call that method to display that button.
Answering my own question here:
In the end, all you have to do is link the view, and the toolbar to the file's owner. You can view a tutorial on how to do that here (in part 3c)

Problem tabbing to field when adding and removing view

I have an scope bar containing a NSSearchField. The bar can be shown and hidden using a menu item. I generate this bar by creating a new NSViewController (and loading a new view from the XIB). When the bar is shown, I do a addSubview: to the window's contentView; when the bar is hidden, I do removeFromSuperview to the view within the view controller.
If when I launch the app and the bar is already opened, hitting tab toggles between the main view within the window (a table view) and the search field in the scope bar. If I launch the app and the bar isn't already shown, once I do show the bar I can tab from the table view to the search field, but not the other way.
Once I remove the scope bar for the first time, then show it again, I can no longer tab between the search field and the table view, no matter which view is currently selected.
Is there something I need to be doing besides addSubview: and removeFromSuperview? I can't wrap my head around why this won't work, and especially why I get different behaviors if the bar is shown on launch or not.
You need to set the nextKeyView of both views if you want to control what happens when you hit the tab key.
[yourTableView setNextKeyView:yourSearchField];
[yourSearchField setNextKeyView:yourTableView];
However, you need to be careful because you can break the automatically constructed key-view loop. This article has more detail on how to handle this situation.
I was able to get the desired behavior by setting setAutorecalculatesKeyViewLoop: to true on the views' window.