Question

I am Developing a sencha Touch application and using phonegap for ios build. I want to show a number toolbar on top of ios keyboard and get the number button action in textField. I can show the toolbar on top of the keyboard but can't update the textFild values according with the button tap/ clik.Here is my code .Please help me to solve this issue. I did the code in MainViewController.m. I am not familiar with objective c.

#import "MainViewController.h"

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShowNotification:) name:UIKeyboardDidShowNotification  object:nil];
    }
    return self;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark
- View lifecycle - (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     // Return YES for supported orientations
     return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

- (void) keyboardDidShowNotification:(NSNotification *)aNotification {
    UIBarButtonItem *my0Button = [[UIBarButtonItem alloc] initWithTitle:@"0" style:UIBarButtonItemStyleBordered target:self action:@selector(addNumberToString:)];     
    UIBarButtonItem *my1Button = [[UIBarButtonItem alloc] initWithTitle:@"1" style:UIBarButtonItemStyleBordered target:self action:@selector(addNumberToString:)];
    // UIToolbar *keyboardToolbar=nil;
    UIToolbar *extraRow = [[UIToolbar alloc] init];
    extraRow.barStyle = UIBarStyleDefault;
    extraRow.translucent = YES;
    extraRow.tintColor = [UIColor grayColor];
    [extraRow sizeToFit];
    NSArray *buttons = [NSArray arrayWithObjects: my0Button, my1Button, nil];
    [extraRow setItems:buttons animated:YES];
    NSArray *array = [[UIApplication sharedApplication] windows];
    for (UIWindow* wind in array) {
        for (UIView* currView in wind.subviews) {
            if ([[currView description] hasPrefix:@"<UIPeripheralHostView"]) {
                for (UIView* perView in currView.subviews) {
                    if ([[perView description] hasPrefix:@"<UIWebFormAccessory"]) { 
                        [currView addSubview:extraRow];
                        [perView removeFromSuperview];
                    }
                }         
            }        
        }     
    }
}

-(void) addNumberToString: (id) sender     {
    // HERE I WANT TO SHOW THE BUTTON TEXT TO TEXTFIELD,
}
@end
Was it helpful?

Solution

Finally i got output.

UIButton *clickButton=sender;
UILabel *label=clickButton.titleLabel;
NSString *buttonText=label.text;

NSString *javaScript = [NSString stringWithFormat:@"var textField = document.activeElement;" "textField.value = textField.value+'%@';" "document.activeElement.form.submit();", buttonText];
[webView stringByEvaluatingJavaScriptFromString:javaScript];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top