who is currently the first responder? (iOS)
Is there a way to find out what UIResponder is the current first responder, the one with the keyboard up? I have a number of editable fields, each on a cell of a table view which is in a UIViewController managed by a UINavigationController. There's a couple of other editable fields on there too, in the top bar. If the user hits the back button, or a button which pushes a new UIViewController on the stack or initiates some other view transition whilst one of those things is being edited, I want to make the edit commit before I leave the screen to get the model object in a consistent state. To do that I need to tell the first responder to resign, if I can figure out what it is. I didn't particularly want to iterate all the fields which could be onscreen or all the views in the hierarchy and tell them all to resign. Is there a way to find the current first responder? I did wonder about just telling the UIApplication itself to become, and then resign, first responder, but that doesn't feel quite right. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: who is currently the first responder? (iOS)
On Wed, 29 Jun 2011 21:12:50 +0800, Roland King r...@rols.org said: Is there a way to find out what UIResponder is the current first responder, the one with the keyboard up? No. I devote some space to ranting about this in my book. The app obviously *knows* who the first responder is, so why won't it tell you? My workaround is to implement delegate methods on all my UITextFields and store a reference to the text field in an instance variable when it starts being edited. Oh, and as I warn in the book, do NOT name that instance variable firstResponder or your app will fall to its knees; guess how I found *that* out? :) I want to make the edit commit Oh. Well, if that's your only problem, then all you have to do is call endEditing: on the superview. m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ A fool + a tool + an autorelease pool = cool! Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: who is currently the first responder? (iOS)
On 29-Jun-2011, at 11:56 PM, Matt Neuburg wrote: On Wed, 29 Jun 2011 21:12:50 +0800, Roland King r...@rols.org said: Is there a way to find out what UIResponder is the current first responder, the one with the keyboard up? No. I devote some space to ranting about this in my book. The app obviously *knows* who the first responder is, so why won't it tell you? Yeah annoying isn't it - I'll file a bug report about that. Googling found a guy who's app was rejected because he found a method which returned it, could do with that being public. My workaround is to implement delegate methods on all my UITextFields and store a reference to the text field in an instance variable when it starts being edited. Oh, and as I warn in the book, do NOT name that instance variable firstResponder or your app will fall to its knees; guess how I found *that* out? :) I want to make the edit commit Oh. Well, if that's your only problem, then all you have to do is call endEditing: on the superview. aagh - thanks - I'd been looking at methods on the view controller for it, like setEditing: etc., didn't find endEditing on the view itself, that should do the trick. The documentation for that says it goes through the view hierarchy finding the text field which is the first responder, so it does what you would naively do, and in this case, they're all text fields so that's ok. let me go put that in and try it out thanks m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ A fool + a tool + an autorelease pool = cool! Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: who is currently the first responder? (iOS)
File a doc bug :) -- Alex Kac CEO/Founder On Jun 29, 2011, at 11:10 AM, Matt Neuburg m...@tidbits.com wrote: Actually it works for more than text fields; another case of poor documentation. m. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com