WKLongPressGestureRecognizer in WKInterfaceTable - swift

I am trying to add a WKLongPressGestureRecognizer to cells in a WKInterfaceTable. But it does not work. The IBActions are never fired.
Is there any trick that I'm missing? Or is this simply not supported on watchOS?

In case it's helpful... I've been battling the same and got to:
Attaching the 'Long press gesture recogniser' under 'Table' in your screenshot, rather than 'Group' and linking to an Action in the WKInterfaceController:
- (IBAction)didLongPress:(id)sender
{
if ([sender isKindOfClass:[WKLongPressGestureRecognizer class]])
{
WKLongPressGestureRecognizer * item=(WKLongPressGestureRecognizer *)sender;
CGPoint p=[item locationInObject];
NSLog(#"long press point: %f , %f. state=%d\n",p.x,p.y,[item state]);
}
}
It's not a final solution, but the action does at least get triggered. Unfortunately when triggered, it stops the didSelectRowAtIndex coming through so it's not easy to figure which row has been long-pressed. My best thought for progressing would be to use the p.y value to determine which row in the table was long-pressed on. I've been trying to figure out how to programmatically determine row heights or translate a location into an object but have so far failed, so for the moment I have given up on this functionality as I don't really want to hard-code a row-height in. But maybe it gets someone else closer to a solution, or fits a situation where row-height can be safely be hard-coded :)
Other routes I tried (and failed), but might be a starting point for others (or save some time):
trying to cancel the long press, so I still get the row-select come through (but I could have recorded we have a long press, so can act accordingly). Unfortunately I couldn't see how to do this. I tried [item setEnabled:false]; but it didn't cancel the current long press. It just stopped all future long presses being recognised.
I looked up programmatically attaching gestures in case this would give greater control than using storyboard. I didn't get anywhere, and my research indicates this is only supported in iOS, not WatchOS.
Attaching a gesture as per the posted question. I too was unable to see evidence of any action code being called :(

Related

swift - how to prevent two touches at the same time

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

Objective-C: Trigger method with computer keyboard stroke

Sorry if the questions is asked/answered already, or if my title is poorly worded.
I am currently writing an iPhone app, and have considered a useful tool for debugging. I would like to write a method that just prints variables and other info that I want. That part is simple and all, but I want this to be called by keystroke.
For now I have been just adding NSLog()'s to viewDidLoad or to other button methods to check if my variables are being set properly, but it's becoming tedious and the code is long so I tend to forget about some and spend a lot of time looking for them haha.
I just want one method that I can go to to write my NSLog()'s, and have that method call whenever I hit 'space' or something of that sort.
Can this be done?
Thanks!
-SF
It's pretty hard to do, you need to have a hidden text field that you keep in focus, hide the software keyboard for it, then listen on its delegate methods for changing text.
An alternative would trigger the code inside applicationWillResignActive: which gets called on application hiding, notification center showing, or double home press.

How do I add a button to the InAppSettingsKit setting view (iPhone/iPad)?

I have been looking at the sample app provided by InAppSettingsKit and I noticed the use of a couple of buttons:
I would like to integrate a single red button in my app called reset, however I'm not sure how to do it. I've had a look at the code in the sample app and I'm a bit lost with it all. Please could someone help me out?
After spending a while searching through all the code and plists I managed to find the answer to my question. For those who are interested what you need to do is the following:
Add a row to your Root.plist file with the Type set to IASKButtonSpecifier.
Set the Identifier on this row as something useful e.g. 'myButton1'.
Add the following delegate method to the viewController you loaded the InAppSettingsKit from:
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForKey:(NSString*)key
{
if ([key isEqualToString:#"myButton1"])
{
// Do some actions...
}
}
It's worth noting that the key is equal to the identifier you set in the Root.plist.
The only thing I haven't worked out yet is how to change the colour of the button; however I suspect this may be possible by overriding a method.
Great that you already found part of the solution. To customize the look, you should create a custom view using the IASKCustomViewSpecifier documented on http://www.inappsettingskit.com/. The yellow icon for instance is making use of this. In your case, you could return an instance of UIButton with a red background color (or a custom background image).
In this case, you don't need the buttonTappedForKey method to get the tap event but configure the target/action of your button as usual.

suppress keyboard in iphone UiWebViews

I have an app that uses UiWebViews, and I need to not show the keyboard for a text field within such a view. I provide my own buttons that insert the limited sorts of text the field allows, but I also need to allow pasting (I will filter what gets pasted) and adjusting the cursor position. Any way to do this?
It looks like this can't be done, I've researched it further and that's pretty clear. I don't want to accept a wrong answer, so I figured I'd just answer this myself and say: can't be done.
if you just want the textField do normal things except the showing keyboard action, you could subclass UITextField and overwrite the touchesBegan/Moved/Ended, just call super touchesBegan/Moved/Ended and add additional code which would hide the keyboard, if you have a reference to the keyboard ( you may figure it out urself how-to ), call the method : [keyboard resignFirstResponder], you may try to Category the UITextField class so you would have the reference to the keyboard ( if it's private ) - but not recommended because categorying may break our project design, but if you just need it for the only purpose, give it a try. Hope it helps.

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values varies. The problem is that the number pad does not contain a key for entering a decimal point.
When I lock my phone, the number pad that comes up to enter a passcode has a custom button to make an emergency call (as seen in the following screenshot):
Numberpad with custom button http://img25.imageshack.us/img25/6426/photoejg.jpg
Does anyone know how to create a number pad with a decimal point button or a custom button (like the emergency call button above)?
Thanks.
There's no Apple-approved way to edit the existing keyboard. If you want them to allow it, file a feature request.
That said, it just so happens that in most applications the keyboard (instance of UIKeyboard) is a separate UIWindow, and you can iterate over the windows in the application and start adding custom subviews that respond to the appropriate touch actions. Find it by iterating over [[UIApplication sharedApplication] windows] and checking to see if the description contains the string UIKeyboard. For more info on this method and some sample code, see this answer.
Another approach is to create your own custom view and build a keyboard from scratch. Be careful if you do this, though, as it requires a lot of manual work, not only in creating the keyboard and getting the touch behavior to match Apple's, but also in any control you add that would bring up the regular keyboard - you'll need to redirect things like becomeFirstResponder to show your own keyboard, rather than Apple's.
Edit: As ZaBlanc pointed out, newer versions of iOS have a way to do this with the inputView and inputAccessoryView properties. See the UIResponder class reference for details.
set UIKeyboardType to UIKeyboardTypeDecimalPad
Available in iOS 4.1 and later.
Create a UIViewController that contains a UIView with a bunch of buttons. Now your keyboard can have whatever you want on it.