【问题标题】:Sencha Touch, Phonegap ,IOS, keyboard top toolbarSencha Touch,Phonegap,IOS,键盘顶部工具栏
【发布时间】:2014-05-09 18:05:57
【问题描述】:

我正在开发一个 sencha Touch 应用程序并使用 phonegap 进行 ios 构建。 我想在 ios 键盘顶部显示一个数字工具栏并在 textField 中获取数字按钮操作。 我可以在键盘顶部显示工具栏,但无法根据按钮点击/单击更新 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

【问题讨论】:

    标签: ios cordova keyboard sencha-touch toolbar


    【解决方案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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多