how to add Notes in on a webview iphone app? - iphone

I have an iPhone application with a UIWebView as it's core UI and this web view shows some data that I want to add notes next to, an example scenario would be:
The User will select a text in the webview and a pop up menu
appears.
They will press AddNotes button.
An UI textview window should appear to write in.
The user should press save and the notes should be saved regarding
the location he press the AddNotes button in.
Can anyone help partially or completely?

This will help you to know about the selected test using the Rangy library:
- (BOOL) isSelectionActive
{
NSString * resultStr = [self.contentView stringByEvaluatingJavaScriptFromString:
#"rangy.getSelection().isCollapsed"];
NSLog(#"resultStr: %#", resultStr );
if ([resultStr isEqualToString:#"true"]) {
return NO;
}
else {
return YES;
}
}
When you get to know that the selection has been made then animate a UITextfield, so that user will be able to enter text in it.

Related

Need to replace UIWebView UITextField keyboard

I'm using UIWebView to display formatted content. However, I need to replace the default keyboard for UITextViews/UITextFields with our own.
I can use grotesque methods to hide the default keyboard when it appears, but I can't find the text field to direct input to. UITextFieldTextDidBeginEditingNotification or UITextViewTextDidBeginEditingNotification is never fired off. I do see UIKeyboardWillShowNotification etc properly emitted.
It is important that the final result be App Store approved.
EDIT:
When the keyboard notification comes, note which HTML element is focused. Then make your view controller first responder.
[self becomeFirstResponder];
Your view controller should become first responder and return your custom input view.
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (UIView*)inputView {
return _customInputView;
}
When your custom input view gets input, you can pass it to the HTML element.
NSString* script = [NSString stringWithFormat:#"element.value += '%#';", input];
[_webView stringByEvaluatingJavascriptFromString:script];

Unable to resign keyboard when using PopOver

In my iPad app there are 3 textboxes where i am using popoverview controller on second text box.
here their are 2 cases
In First Case:
As i finish editing the first textbox and click the next button on keyboard that time the keyboard is resigning perfectly and the popoverview controller is opened on second text box.Here i had written the code when the next button of the first textbox click at that time the second textbox should became FirstResponder.
In Second Case:
Here the actual problem,
When i finish editing the first textbox and directly touches the second textbox without clicking the next button on keyboard, that time popoverview controller menu is opened on second textbox and the keyboard is unable to resign , the keyboard is strucking over their my code for resigning the keyboard is not working.
Write your code which you used on NEXT button event of Keyboard in this bellow method...
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
if (textField == yourFirstTextBox) {
// write your code here
}
return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textfield
{
if ([textfield tag]==yourtextfieldtag)//set tag for your textfield
{
[yourfirsttextfield resignFirstResponder];
[yoursecondtextfield resignFirstResponder];
.
.
.
//Write all textField with resignFirstResponder
}
}
Here is the way you can handle your SoftKeypad
Handling Soft Keypad in iPhone Tutorial
There are three simple ways to handle keypad here
Keypad go back when Button clicked.
Keypad go back when user click on Return or Done button on keypad.
Keypad go back when user Touch on Background screen/view.
Just follow 3rd way in you case.
What you need to do is just crate a method in which call
method for the desired text field.
and Updated Related UIView class to UIControl in Interface Builder.
as I have written all the information step by step to make it more easy and clear.
Here is the responsible code snip
- (IBAction)keypadGoBack:(id)sender {
[userNameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
}
Hope this will help you.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField==yourTextField)
{
[self.view endEditing:YES];
// Write Your Popoverview Code / Extra Code
return NO;
}
return YES;
}
Here this method will get called when you will hit textfield.
And check the textfield with yourtextFieldName if its match..it will resign all keyboard.if there is more than one also..with the help of.
[self.view endEditing:YES];
And you can do Extra Code also For popoverview and return no means It will not give keyboard to that perticuler textField.
Thanks.

How to make UITextView text all selectable and show copy option to the user iPhone app?

Am working in iPhone application like iMessage native app. I have designed a page look like iMessage with added a bubbles also. How i done is, just added a UITextView in UITableView Cell and also i have added UIImageView on UITextView with bubble images.
Load the text to UITextView from NSMutableArray. It is working fine. Now my doubt is:
In iMessage app they set that when the user hold the bubble they making the text as selectable and showing Copy option. In my app when the user hold a bubble the Copy option showing but some particular text only copying. How can i select all text and show copy option the user?
In iMessage app the selecting region (two lines in beginning of selection and end of selection) not showing. But in my app the selection regions are showing how can i manage that?
Could you please help me to solve this issues? Thanks in advance.
Finally i have solved my problem used below code. Now am able to select all content from UITextView and showing Copy option to the user to copy the message. Please find the code for your reference.
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(copy:))
{
[self selectAll:self];
return YES;
}
else if (action == #selector(cut:))
{
return NO;
}
return NO;
}
- (void)copy:(id)sender
{
UIPasteboard *pastBoard = [UIPasteboard generalPasteboard];
[pastBoard setString:self.text];
self.selectedTextRange = nil;
}
Happy Coding.
Here, How you can select text in UITextView
[textView setSelectedRange:NSMakeRange(row, length)];
where, row indicates from which row you want to start your selection. length is total length of text.
e.g. [textView setSelectedRange:NSMakeRange(1, 45)]; // where 1 is first row, and 45 is length of text of selection.

How can I determine which of two buttons is pressed by the user in the ABUnknownPersonViewController?

I have a button where if user press I am showing ABUnknownPersonViewController. Now the problem is there are two options Create New Contact & Add To Existing Contact. How can I determine which of the options is selected?
I need to know this because in my app, I am showing my contacts in another portion. Some times it causes my app to crash with the error:
Shouldn't be trying to show more than one Add to Existing Contact people picker
How can I solve this problem?
Assign tag value to the buttons and check the tag of the button clicked. Put condition according to the tag and show your views.
- (IBAction)contactsEdit_New:(id)sender
{
if ([addExitingBtn tag]==0)
{
// load ur view for exiting
}
else // here you can add if condition if required
{
// load view for creating new
}
}
Hope this hepls.
I am guessing you have 2 UIButtons?
Give each of them a tag and point them out to one method. If you're using IB just CTRL drag to your code (.m file).
Something like this:
- (IBAction)buttonPressed:(UIButton *)sender {
switch (sender.tag) {
case 0:
// load create controller
break;
case 1:
// load add controller
break;
default:
break;
}
}
You could also try and compare the text on the buttons titlelabel, though I don't really think that's good practice since the text on buttons can change during development.
- (IBAction)buttonPressed:(UIButton *)sender {
if([sender.titleLabel.text isEqualToString:#"create"]) {
// load create controller
} else if ([sender.titleLabel.text isEqualToString:#"add"]) {
// load add controller
}
}
You could also create 2 different methods for each button :)
This way you can avoid using tags since both buttons have their own method to answer to.
Good luck.

iPhone iOS 4 UIButton toggle highlighted state on and off

I got a UIButton with style "Info Dark" set up in interface builder in my iPhone 4 app. One of the properties of the button is "Highlighted", which displays a white highlight around the button.
I would like to toggle this white highlight on and off, indicating if the button function is active or not.
The button is linked for "Touch up inside" event in the interface builder with this callback:
infoButton.highlighted = !infoButton.highlighted;
After the first touch, the highlight disappears and does not toggle as I expect it to. What else do I need to do to make the highlight toggle and display the state of the button?
Thank you!
Update:
When loaded from the interface builder, the button stays highlighted, even as the view appears/disappears. What causes this to happen is the "shows touch on highlight" interface builder property. If I assign the code above to another button, the info button highlights on and off as expected. However, the touches of the info button itself interfere with the above code, causing the button to lose the "touch" highlight
Update 2: I added another info button, directly below the first info button, in the interface builder and made it glow permanently. To create the appearance of the toggle, I hide and unhide the glowInfoButton below the real one. This works as expected:
infoButton.highlighted = NO;
glowInfoButton.highlighted = YES;
glowInfoButton.enabled = NO;
glowInfoButton.hidden = YES;
- (IBAction)toggleInfoMode:(id)sender {
// infoButton.selected = !infoButton.selected;
glowInfoButton.hidden = !glowInfoButton.hidden;
}
The Highlighted image is what displays when the UIButton is being pressed, and is controlled within the UIButton itself.
You're looking for the Selected property. You can set a Selected Image in IB, and then put a infoButton.selected = !infoButton.isSelected; in your TouchUpInside callback.
The highlighted property doesn't work like that, buttons aren't toggles.
It's just to know if the button is being pressed, if I'm correct.
If you want to implement that functionality, I recommend you subclass UIButton or UIControl.
Now that I see what you really were after I would advise subclass UIButton and check for a call to an event then toggle highlight state accordingly. You can do this without adding the dummy button.
in a custom button class implementation file place the following code, or similar:
#import "HighlightedButton.h"
#implementation HighlightedButton
BOOL currentHighlightState;
-(void)toggleHighlight:(id)sender {
self.highlighted = currentHighlightState;
}
-(void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event {
//get the string indicating the action called
NSString *actionString = NSStringFromSelector(action);
//get the string for the action that you want to check for
NSString *touchUpInsideMethodName = [[self actionsForTarget:target forControlEvent:UIControlEventTouchUpInside] lastObject];
if ([touchUpInsideMethodName isEqualToString:actionString]){
//toggle variable
currentHighlightState = !currentHighlightState;
//allow the call to pass through
[super sendAction:action to:target forEvent:event];
//toggle the property after a delay (to make sure the event has processed)
[self performSelector:#selector(toggleHighlight:) withObject:nil afterDelay:.2];
} else {
//not an event we are interested in, allow it pass through with no additional action
[super sendAction:action to:target forEvent:event];
}
}
#end
That was a quick run at a proper solution, there is a flicker on toggle that you may not like. I am sure if you play around with some changes that can be corrected. I tried it and actually like it for your stated case.
The highlighted state of a UIButton is simply setting the button's alpha to 0.5f. So if you set the button to not change on highlight, then just toggle the alpha between 0.1 and 0.5.
For example:
- (void)buttonPressed:(id)sender {
if((((UIButton*)sender).alpha) != 1.0f){
[((UIButton*)sender) setAlpha:1.0f];
} else {
[((UIButton*)sender) setAlpha:0.5f];
}
}
Perhaps what you really want is
infoButton.enabled = NO;
This will dim the button and disable touches when set to no, allow normal operation when set to YES.
or in your case:
infoButton.enabled = !infoButton.isEnabled;
to toggle the availability of same.
If you put this in your touchupinside event, of course it will work only the first time. After that is disabled and does not receive touch events. You would put it in another method that decides whether or not the button should be enabled.
If you truly want it to change each time it is pressed then you probably should use a switch or you may look at the -imageForState, -setTitle:forState and/or -setTitleColor:forState methods. If you want to toggle the appearance each time it is touched, you could change these.