How to deselect selected text in an iPad application - ipad

I have a custom menu item (UIMenuItem) attached to a UIWebView. When the user selects my custom menu item after selecting some text in the web view, I want to "deslect" the current text selection. The problem is that the edit menu will pop up again when I show a modal form for some reason, I think because there is still a selected (highlighted) text range. I want to programmatically "unselect" the selected text in my custom menu item handler, after I've captured the selected range.

Use UIView's userInteractionEnabled property. Just disable user interaction and enable it back.
Like this:
myWebView.userInteractionEnabled = NO;
myWebView.userInteractionEnabled = YES;

A cleaner solution:
Swift
webView.endEditing(true)
Objective-C
[webView endEditing:YES]

Related

How can I bring the tableview in front of all views?

I have a viewcontroller which i am showing as a popup. The popup has two textfields with dropdown(the dropdown is a tableview which is subview of superview).So whenever I show the dropdown it is just taking the height of popup and the complete dropdown is not visible so the user is not able to select value from last rows.So I want to show the dropdown in front of all views so that the complete dropdown will be visible and the user will be able to select any value. I tried [self.view bringSubviewToFront:self.tableView]; and self.tableView.layer.zPosition = 1; both did not help me. How to do this?
Here is the screenshot
Add tableView to the window.
let window = UIApplication.sharedApplication().keyWindow!
window.addSubview(tableView)

UISegmentControl Customisation

I want to customise UISegmentControl according to link of the screenshot(Shows is selected and News is unselected) given below:
UISegmentControl Customisation
Segment with Title and Image
Borderless segments
Tap event even if Segment(Shows) is selected - I want to perform some action if user tap on selected segment
[SegmentedControlName setImage:[UIImage imageNamed:#"path"] forSegmentAtIndex:0];
For selected event you can use same thing when it also on the touched state.
Only you need to change is the path of the image
I ended up using the following library. It fulfilled my all the requirements.
PPiFlatSegmentedControl

How to set focus from one UIButton to Another UIButton in UIToolbar Done Button

I am working with iPhone Application with creating single object multiple dynamic button in UITableView. And when user will press button every time UIDatePicker will open to select date. So Is is possible to move focus from one UIButton to another UIButton after date selection. I am explaining you in detail as follows:
I have create UITableView with single object Multiple Custom UIButtons. When user will click on all this button the UIDatePicker will show with Next and Cancel UIToolBar. When user select date from datePicker and press Next button i want focus or select for the next UIButton to give facility to select date from datePicker for another button. Like flow without removing view for transaction.
So is it possible to Focus on another button after pressing Next button to another button.I googled around but could not find any solution for this.
Please help me for this.
Yes You can.. Perform following steps:
Set Different style for your buttons for Highlighted state.
Give a unique tag for each Button.
Lets say you have 5 buttons with tags 0 to 4. In your TouchUpInsideEvent write this,
(IBAction)onButtonClick:(UIButton *)sender
{
for(UIButton * btn in myButtons)//Mybuttons is outletCollection of buttons
{
if (btn.tag == sender.tag + 1)
{
[btn setHighlighted:YES];
break;
}
}
}
If it does not work with Highlighted state, you can try with Selected state. (I think it will work with selected state only .. :))

How do I set a UITextField as the default input field at app launch

I am writing an iPhone app with a keypad and two TextFields on a single view. The user types into each of the text fields. Because I want to use an on-screen keypad, I disabled the the keyboard from launching when each TextField is selected. (I used the method suggested in this thread:
Disable UITextField keyboard?
So far so good EXCEPT the cursor doesn't blink in the either of the two TextFields until they are selected. If I just begin typing without selecting, the first textfield is filled. That's OK, but I would like to set the cursor flashing in that field so the user is notified that that is where the input will go unless they select the other field.
I did not create the text fields programatically. I created them with Interface builder.
How do I programatically select the desired starting text field (ideally some highlight would show up when selected). Right now I just got lucky and the field I want to be the default is the default.
How do I place the flashing cursor onto the right side of that text field.
...Dale
Call [myTextField becomeFirstResponder]; this will notify the receiver that it is about to become first responder in its window. That should set the Cursor in the UITextField.
To programmatically activate a field and make it your starting text field you should use UIResponder's becomeFirstResponder method, which all UITextFields inherit from.
[textField becomeFirstResponder];

Deleselect uisegmentedcontrol selection after clicking on a save button

I'm using a 3 button UISegmented control for a choice selection. I also have a save button that retrieves the chosen control.
When the save button is clicked I want to have to UISegmentedcontrol cleared (ie the previous selected button unselected). I'm not looking for the setMomentary as I want the selection to stick but also be able to unselect it later.
[myUISegmentedControl setSelectedSegmentIndex:UISegmentedControlNoSegment];
myUISegmentedControl.selectedSegmentIndex = -1; //turn off the current selection
With Swift 4 and iOS 11, the Apple documentation states for selectedSegmentIndex:
The default value is UISegmentedControlNoSegment (no segment selected) until the user touches a segment. Set this property to -1 to turn off the current selection.
Therefore you can use one of the two following implementations in order to remove the selection of your UISegmentedControl instance:
mySegmentedControl.selectedSegmentIndex = -1
mySegmentedControl.selectedSegmentIndex = UISegmentedControlNoSegment

Resources