Sencha Touch,Phonegap,IOS,键盘顶部工具栏

时间:2014-05-09 18:05:57

标签: ios cordova keyboard sencha-touch toolbar

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

1 个答案:

答案 0 :(得分:1)

最后我得到了输出。

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