I'm an iPhone dev newbie, and I'm having a problem slightly similar to a few posts I read around here, but none of them seemed to help.
I have created a UIScrollView, with a UIView as its content (a subview). During runtime, the UIView is populated with labels and buttons. Everything looks fine, scrolling works perfectly, but the UIButtons never fire when pressed, no matter what I do. I've tried many combinations of properties suggested here, to the best of my understanding, but still nothing worked. I'm afraid I might have misunderstood something about the mechanism.
I should mention that everything is done in code (no IB).
Any suggestions?
My bug (written in the comments of my question) was not setting the frame of the contentview that was the parent of all buttons. The result was strange - I could see the button subviews (which was why it took me a while to find the bug) but could not click on them. oops!
This also may happen, when your custom UIView userInteractionEnabled is NO (default is NO).
try [btn becomeFirstResponder];
Related
I have created a simple test project with a single UITextView and the touchesBegan method in the view controller. For some reason, the UITextView is not responding to touchesBegan.
Things I have tried:
Alpha is set to 1
User interaction is enabled on the view and the UITextView
Delay Touch Down is unchecked
The background is set to a solid color
I found similar questions in several places, but none of the solutions have worked.
While it seems like others have successfully gotten touchesBegan to work on a UITextField in the past, nothing seems to be working now. Instead, I simply added textFieldDidBeginEditing and canceled the animation from there. Problem solved.
I have a subview that acts as a container view in a table header. In that, I have a UIButton. The button is not receiving any touch events. (Yes everything is wired up properly in IB...)
So my question is, is it a common problem to have buttons not receiving any events in the header? Do I need to forward any events?
I can't really post any code, since it would appear to be more of an IB problem. Anyone experience this before?
UPDATE: If I put the button in the footer, with no container view, it will work. So perhaps it's because it is in a view inside the header??
Wow, I feel like a moron. I didn't have user interaction enabled. Sorry for wasting all your time guys...
I've included UIButtons and even UITableViews in my table header before, so I don't think it should be an issue. Something is just not setup correctly. I didn't have to do anything special to get touch events to fire.
Kinda confusing title but oh well.
I have a UIScrollView in my viewController, in that is 3 UIViews with some buttons in each. I download data from a server and populate it into the view and this works as soon as you start scrolling the UIScrollView, but sometimes the buttons only partially load.
Usually its the button label without my formatting added to it. The button works and as soon as you click the button the rest of view loads correctly. Basically if the UIScrollView is touched in anyway it displays correctly.
I've tried adding and removing the scrollView to the view and I've called [scrollView setNeedsDisplay] and the exact same thing happens.
Anyone come across this?
EDIT: screen shot before and after (just basic to demonstrate whats happening)
I was building the buttons in drawRect which was causing issues. Built the buttons in a separate method and it worked fine.
I have run into an interesting bug where it appears that when you select a UITableCell it changes all of it's subviews to their highlighed state. This includes my accessoryView which is a UIButton which obviously I only want highlighted when the user presses like a normal button.
I have a friend who went as far subclassing UIButton to override this in his app and manually managed the state for this type of behavior but that seems drastic to get what should be the expected behavior. So, I am wondering what other solutions people have come up with for this problem.
Has anyone else had this issue? If so, what did you do to work around it? Any code samples as well as ideas are very welcome!
I ended going with a custom button on this like Jesse Recommended abd set both the highlighed and normal state to the same image. It seemed to work well enough for what I was trying to do. Thanks again!
I'm building an iPhone application and like most I am trying to implement a UIScrollView with a UIPageControl, however I am coming across a very quirky behavior, which I assume may be a bug. Hopefully one of you has seen this before because it is driving me nuts.
Basically, the page control works fine, everything is hooked up and works normally on all accounts EXCEPT, with certain placements of the UIPageControl within the UIView, the UIPageControl will cease to render.
I'll just take screenshots of the XIB window to help illustrate... here's a placement that works perfectly fine:
http://www.jasconi.us/prob1.png
The UIPageControl is placed physically above the UIScrollView. Works great, everything is visible and working.
The next two DO NOT work:
http://www.jasconi.us/prob2.png
http://www.jasconi.us/prob3.png
The first one is simply placed below the scroll view. Doesn't render at all.
The second one is placed above the scroll view without technically being inside of it. Also doesn't render.
What the hell is up with this? I've tried using
[[self view] bringSubviewToFront:pageControl];
...to no avail.
Any ideas?
OK I found the answer to this, it's a little six degrees of Kevin Bacon.
This isn't actually a software bug, but a XIB quirk, for some reason the lower placement of the page control in combination with the default settings for autosize and anchor seem to jettison the control into outer space.
If you turn off all auto-scaling and auto-sizing and auto-anchoring and all that other crap, the controls appear exactly as you expected. The fact that it appears reliably when placed above the ScrollView is an oddity.
shrug.
Hope this helps future iPhone initiates.
Did you check to make sure that numberOfPages is not 0?
If you set a breakpoint can you see that pageControl is not nil?
I was still encountering this exact same problem, even after trying everyone's posted answers. My issue ended up being a little more "DOH":
I was using UIPageControl at the bottom of a modal FormSheet, however, I forgot to set the size of the view as Form Sheet in the xib. This caused my page control to be off the screen and never visible.
Moral: set view size (Full, Form, Page, etc) in your xib on the base view.
This will sound like a real no brainer, but I got caught out by it.
By default, UIPageControl expects to be on a dark background. IE: The dots are light gray, and white for the current page.
I used UIPageControl on it's own with no scrollview to change the time range of a graph I was rendering with drawRect:
Long story short, the graph background was white, so the page controller worked, I just couldn't see it. The solution was putting the graph itself in a subview, and making the parent that contained the page control have a dark background.