Any way to know if UITextField is in the view's hierarchy? - ios

I am creating a UITextField-A inside an inputAccessoryView and when I call [UITextField-A becomeFirstResponder], it would not work. However, if I do it with a delay of 1 sec, it would work. From what I searched, it is because the UITextField is not in the view's hierarchy yet. So is there a way to know so I do not need to use the 1sec delay alternative? Is there a UITextFieldDidAppearInViewHierarchy or somekind in the SDK?

UIView offers a didMoveToSuperview method that you could abuse to do this.

Related

UIScrollView+UIView instead of UITableView+customcells?

I need UIView created automatically when scrolling happens. One UIView disappear and one UIView appear. Invisible UIView should be unloaded from memory like than I use UITableView and loaded back than I scroll back. Is it possible?
Absolutely possible, you can just reference the UITableView,including its datasource and delegate methods
Checkout my example of RecyclingScrollView
https://github.com/iSevenDays/RecyclingScrollView/tree/new

How to make UITextView register touches when it is currently first responder?

I need a way to know when a UITextView is touched while it is first responder. I have seen some threads about this but I have never figured out how to make it work. I'm assuming there must be a way? Any input would be much appreciated thanks!
rc
UITextField is a subclass of UIControl, so you can add yourself as listener for events using addTarget:action:forControlEvents:.

iOS subview not forwarding touches.

I have tried this a few different ways but none of them seem to work. I have a UIView subclass that has some buttons in it. I tried adding the subview to my ViewControllers however it will not respond to touches unless I set it to "initWithFrame:self.view.frame" but then it takes All of the touches and does not pass them to the view controller. I also tried adding it directly to the window so it's on top of all of the view however I have the same issue, either it will not accept touches or it takes them all.
here is how I add it when it takes all touches for itself and does not pass them on.
ControlView *cont = [[ControlView alloc]initWithFrame:self.window.frame];
[self.window addSubview:cont];
I'm so confused as to how to fix this and I have a lot more important tasks to work on but I have been stuck for two days with this stupid subview/touch issue.
How are you handling touches? UIGestureRecognizer?
You should make sure that your uiview subclass has userInteractionEnabled = YES. That's the default but maybe it got turned off somewhere along the line.

UIwebview does not respond to touchesBegan

I have subclass of UIViewController which has UIWebview as a subview added.
I'm trying to detect touch events on webview but failing to do so.
-(void)touchesBegan
is the method which should get called.
Can anyone help me in this.
Thanks in advance.
Detecting touches on UIWebView is not trivial.
Check this tutorial : http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/
BTW - If you need only to detect a touch on a links or buttons and add a custom action you can do it to. look here:
http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/
Good Luck
Make sure your UIWebView is the first responder. When you add it, use becomeFirstResponder on the web view (I've linked the documentation at Apple for you).
Also make sure becomeFirstResponder returns YES.
Lastly, make sure your view controller's UIView userInteractionEnabled property is set to YES.

linking UIProgressView with IBAction

Perhaps I'm missing something here, but I want the user to be able to select a UIProgressView and thus have an IBAction function call (essentially make it behave like a UIButton).
This can't be rocket science, but I can't figure it out.
BTW, I have xCode 4.
Add a gesture recognizer. With UITapGestureRecognizer you can make any UIView (or subclass) instance respond to taps. You'll have to do it in code instead of in IB, which means you'll need an IBOutlet connection to the progress view. You might need to set userInteractionEnabled to YES to make it work.
It's kind of hard to imagine a scenario where this makes sense, but I'll just assume you have a good reason and leave it at that.

Resources