In our app, in some cases, textFieldDidEndEditing is not being fired. After some debugging, it was easy to see the reason why....textFieldShouldEndEditing was returning NO when the current field is deemed invalid or in other words returning no from textFieldShouldEndEditing.
In the normal case, this behavior works just fine. However, if the user tries to cancel out of the form all together without every fixing the data problem flagged in textFieldShouldEndEditing, some critical code in textFieldDidEndEditing is never being called because that event never fires if textFieldShouldEndEditing=NO;
Can anyone provide some suggestions on how to deal with this case?
Thanks.
Do an [yorTextField resignFirstResponder]; when user try to cancel.
this seems to work....setting an instance variable when the user presses cancel and then using that in textFieldShouldEndEditing ie. = YES
Related
For example, I have 2 buttons Change email and Change password, and each of them call functions with Alamofire request, and responce data should reload both the UI and data scheme.
The point is that this PUT requests change not only servers's data, but generate new token and get updated user's profile.
And when pressing buttons at the same time, at the same moment touches begin and end, app crash after parsing requests.
I'm blocking another UI elements(like textfields), I was trying to block another button, but when press it together, it's not works.
So how can I prevent the same time touch? I'm not good at OperationQueue, maybe thats'the way? Is there an option to check if operation not first at the queue and kill it?
Set isExclusiveTouch of your UIButton to true in order to trigger only one button action in a specific time.
This code will get all the buttons contained in the view and set the exclusiveTouch to true:
self.view.subviewsRecursive()
.filter { $0 is UIButton }
.forEach { $0.isExclusiveTouch = true }
This problem with the UIResponder object is very usual. However, your problem description is not clear and your implementation seems not so good.
Here, to resolve this quick touch event problem:
Your solution is debouncing the action event of UIButton.
Debouncing also helps to prevent multiple executions when a user mistakenly pressed a button (or any UIResponder object) multiple times so quickly that even the UI was not blocked till then. Following article may guide you more regarding the same:
Debouncing to tackle repeating user action
I am detecting whether the user has accepted the request to use location services in my app, I have a toggle switch in the UI that is dependent on this acceptance. The first time they toggle the switch (on) the request to use location is triggered. I want to know which button they press in that alert. (accept or decline) Right now I'm just toggling it off and making the user press it again (then detect which option they picked).
It is kind of sloppy that way, so I'd like to know if there is a way to detect this specific alert or can't that be done since it is triggered by the OS, not the application? I haven't tried it yet, but was thinking I could use the UIAlertView delegate methods for just generic button presses, but was hoping for something more specific.
UPDATE
I was able to get this working by just registering a notification when I trigger the location request (and the authorization prompt is shown). The application is placed in an inactive state (much like pulling down the notification bar). I just trigger a notification when the application becomes active and I'm able to just query the authorization status there and update my UI. I hope this helps anyone else down the line if they want to handle the authorization status on the fly.
There is no way to intercept the alert. There is, however, a method on CLLocationManagerDelegate method called didChangeAuthorizationStatus. That's probably the closest you can get to intercepting the alert.
There is no way to know explicitly which button the user selects since, as you've said, this alert comes from the OS. You can however, find out if location services has been enabled for your app, and know that way. Use a method such as this:
-(BOOL)locationServicesIsEnabled
{
if (![CLLocationManager locationServicesEnabled] || ![CLLocationManager authorizationStatus])
return NO;
return YES;
}
I am working on a large (>30k lines) event-driven app. I have a sequence of inputs that produces a bug. What I want to do is to break as soon as the final input enters my code.
Is there a general way to do that?
I understand that for any specific sequence of inputs, I can find out where that last input is going to enter my code, then set a breakpoint there. What I would like to do is take out the step of "find out where that last input enters my code." In other words, I am running the app in the simulator, and I want to set a flag somewhere that says "break the next time you are going to enter non-system Objective C code." Then I send the event that causes the problem.
I understand what you are asking, but have you tried using an Exception Breakpoint? This will basically act like an auto-inserted breakpoint on the piece of code that throws the exception. If that doesn't work for you, try a symbolic breakpoint
If you want to intercept UI events, you can try subclassing UIWindow and overriding its sendEvent: method, then setting this class as the class of the UIWindow object in your main XIB file. sendEvent: will be called each time the user generates a touch event. Unfortunately, at this point you cannot yet know which UI object will finally consume the event (read: which event handler code will be ultimately called) since that depends on the actual state of the responder chain. But anyway, you can use this method to inject events into the system.
As can be seen in the screencast below, I'm having a devil of a time getting webView:shouldStartLoadWithRequest:navigationType: to be called consistently.
In the screencast below, you'll see a UIWebview with three size selectors. When clicking on any of these three, webView:shouldStartLoadWithRequest:navigationType: should be getting triggered. Unfortunately, that doesn't always seem to be happening. It doesn't event seem to happen consistently.
http://screencast.com/t/ww6uwP1Je
So what's causing this? Is there an error method of UIWebViewDelegate that I could hook into to pick up some of what's going on internally?
It seems like you aren't setting the UIWebViewDelegate properly. I noticed in the screencast that it worked once you clicked the 'L' (presumedly "large") button. Is that method setting the delegate? If not, please paste a code snippet that shows the issue.
Since the other two buttons generate calls to the delegate we know your web view delegate is properly assigned.
The simplest explanation for the failure is that S button is not configured in HTML properly and does not generate a actual request for the web view to load. With no request, the delegate methods are never called in the first place.
Ok, turns out I didn't provide anyone enough information for anyone to answer the question - I even removed the relevant parts from the webview gist given above. Sorry!
Here's the full template:
https://gist.github.com/521d17e0377133725d9a
Turns out there was an onclick handler on the li surounding the link (see the gist above - "#sizes_slider li"). Removing that onclick handler did the trick.
I have a UITextFieldDelegate that does a whole bunch of validation on user input to determine whether or not they should be allowed to end editing. In one particular example, it is not valid to leave the field blank.
Right now I'm using textField:shouldChangeCharactersInRange:replacementString: to validate the text input after each edit by the user.
The problem is this: if the user clears the field (with the little 'x' button), the validation code goes into "invalid" mode and prevents the user from navigating away until they have entered valid text. If the user then shakes the phone to get the old text back, shouldChangeCharactersInRange is not called again and the delegate stays in the "invalid" state instead of recognizing that everything is fine again.
Not sure if I'm using it correctly, but it seems like the built-in UITextFieldDelegate machinery is not able to cope with text changes due to undo / redo.
What's the best way to achieve proper validation in this scenario? Do I really need to subclass UITextField in order to implement motionEnded:withEvent:? Seems like the edit-handling stuff in UITextField should really be independent of whether the user actually typed it or it happened due to undo, so would be bummed if I actually had to go that route.
Hook up a method to the UIControlEventEditingChanged event ("Editing Changed" in IB -- not "Value Changed").
This appears to fire whenever/however the text field changes.