我正在开发sencha Touch应用程序,并使用phonegap进行ios构建。
我想在ios键盘顶部显示一个数字工具栏,并在textField中获取数字按钮操作。
我可以在键盘顶部显示工具栏,但无法使用tap / clik按钮更新textFild值。这是我的代码。请帮助我解决此问题。我在MainViewController.m中执行了代码。我对 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

最佳答案

终于我得到了输出。

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];

08-16 16:14