0

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:

Search view of app

This is the SearchView.xib file's hierarchy in Interface Builder

Screen shot of view hierarchy

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.

Pete
  • 4,542
  • 9
  • 43
  • 76
  • I suspect that the subview you add in (3) covers the button and takes all of the events even though it is hidden. Is the view in (3) taking the whole height of the app? – Resh32 Aug 31 '12 at 15:10
  • Not the full height, but from above the tab bar up until the big logo at the top, so it does site over the "How to search" – Pete Aug 31 '12 at 15:15
  • Ah, I've just found a comment in this question: http://stackoverflow.com/questions/5024260/uiview-hidden-property-is-there-more-to-it that points out views that are hidden still accept touch events... am I going to have to remove it completely, or can I set a view to hidden and something like inactive? – Pete Aug 31 '12 at 15:17
  • Does the order of the items in the view make a difference? If I put the "How to search" button under the view will that help? – Pete Aug 31 '12 at 15:28
  • 1
    Yes, view order is definitely affecting the touch sequence. – Resh32 Aug 31 '12 at 15:34

1 Answers1

1

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.

esreli
  • 4,993
  • 2
  • 26
  • 40
  • Not sure where I'd put that in the code. Also, if the view is set to `hidden = YES` then would the over lap still matter? – Pete Aug 31 '12 at 15:14
  • Actually I know it overlaps it anyway, it definitely does. – Pete Aug 31 '12 at 15:17
  • So that seems to be the problem. If you create an IVAR pointing to that view you could remove all subviews from superview and then remove it from superview. In fact, I would recommend that. – esreli Aug 31 '12 at 15:22
  • you put this code just after you create the view and add it as a subview – esreli Aug 31 '12 at 15:23
  • I never add it as a subview, State 3's view is built using interface builder. It's just a view with a message and a link to a website, it has nothing dynamic in it, so I've built it with IB and I just set it to hidden = YES/NO as and when I need to see it. – Pete Aug 31 '12 at 15:24
  • are you completely set on using this method? You have much more control if you do it in code rather than IB – esreli Aug 31 '12 at 15:25
  • It's just such a simple view I thought it'd be fine in this case. The view is still assigned to a referencing outlet, I can still interact with it. If there's no solution I'll have to remove it from the stack and add it back in, but it never changes so that seems unnecessary to keep recreating it. Or am I missing something, can I create it once then remove it from the view stack without actually removing the object from memory? – Pete Aug 31 '12 at 15:32
  • you could also move the How To Search button to the top of the stack. I'll modify my answer. – esreli Aug 31 '12 at 15:37
  • That's the ticket, if I rebuild the app I'll just do it programatically, I agree that's easier overall, but I'll just use `bringSubViewToFront` and `sendSubViewToBack` on the State 3 view when I show and hide it, works perfectly. Thanks. – Pete Aug 31 '12 at 16:09