iOS在UIWebView表单输入中使用UIKeyboardTypeDecimalPad
我想在基于cordova的应用程序中,在本机应用程序使用的左角显示带“.”的小数点 我已经看到很多线程使用私有API等,但我想要一个解决方案,将用于应用商店提交。感谢您的帮助 我已经从线程中尝试了一些内容。 下面是我的修改iOS在UIWebView表单输入中使用UIKeyboardTypeDecimalPad,ios,cordova,uiwebview,Ios,Cordova,Uiwebview,我想在基于cordova的应用程序中,在本机应用程序使用的左角显示带“.”的小数点 我已经看到很多线程使用私有API等,但我想要一个解决方案,将用于应用商店提交。感谢您的帮助 我已经从线程中尝试了一些内容。 下面是我的修改 @protocol TSPingPong <NSObject> - (void) ts_pong: (id) sender; @end @interface NSObject (TSPingPong) @end @implementation NSObject
@protocol TSPingPong <NSObject>
- (void) ts_pong: (id) sender;
@end
@interface NSObject (TSPingPong)
@end
@implementation NSObject (TSPingPong)
- (void) ts_ping: (id) sender
{
if ( [sender respondsToSelector: @selector(ts_pong:)] )
{
[sender performSelector: @selector( ts_pong: ) withObject: self ];
}
}
@end
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(keyboardWillAppear:)
name: UIKeyboardWillShowNotification
object: nil];
NSString* html = @"<br><br><br><form action=''> " \
"First name: <input type='text'><br> " \
"Last name: <input type='text'><br>" \
"<input type='submit' value='Submit'> " \
"</form>";
[_webView loadHTMLString: html
baseURL: nil];
}
- (void) keyboardWillAppear: (NSNotification*) n
{
// the keyboard is about to appear!
// play pingpong with the first responder so we can ensure it has a keyboardAppearance method:
[[UIApplication sharedApplication] sendAction: @selector( ts_ping:) // added via category extension
to: nil // to: the first responder
from: self // "sender"
forEvent: nil];
}
- (void) ts_pong: (id) sender
{
// sender is the first responder. Happens to be undocumented "UIWebBrowserView" in this case.
// if it doesn't have it's own keyboardAppearance method then let's add one:
if ( ![sender respondsToSelector: @selector(keyboardAppearance)] )
{
Method m = class_getInstanceMethod( [self class], @selector( keyboardAppearanceTemplateMethod ) );
IMP imp = method_getImplementation( m );
const char* typeEncoding = method_getTypeEncoding( m );
class_addMethod( [sender class], @selector(keyboardAppearance), imp, typeEncoding );
}
if ( ![sender respondsToSelector: @selector(keyboardType)] )
{
Method m1 = class_getInstanceMethod( [self class], @selector( keyboardTypeTemplateMethod ) );
IMP imp1= method_getImplementation( m1 );
const char* typeEncoding1 = method_getTypeEncoding( m1 );
class_addMethod( [sender class], @selector(keyboardType), imp1, typeEncoding1 );
}
}
- (UIKeyboardAppearance) keyboardAppearanceTemplateMethod
{
return UIKeyboardAppearanceDark;
}
- (UIKeyboardType)keyboardTypeTemplateMethod
{
return UIKeyboardTypeDecimalPad;
}
@protocol-TSPingPong
-(无效)ts_pong:(身份证)发件人;
@结束
@接口NSObject(TSPingPong)
@结束
@实现NSObject(TSPingPong)
-(作废)邹平:(身份证)发件人
{
if([sender respondsToSelector:@selector(ts_pong:)]))
{
[发送方执行选择器:@selector(ts_pong:)with object:self];
}
}
@结束
@界面视图控制器()
@属性(弱、非原子)ibuiwebview*webView;
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
[[NSNotificationCenter defaultCenter]添加观察者:self
选择器:@选择器(键盘将显示:)
名称:UIKeyboardWillShowNotification
对象:无];
NSString*html=@“
”\
“名字:
”\
“姓氏:
”\
" " \
"";
[\u webView加载HTMLSTRING:html
baseURL:nil];
}
-(无效)键盘将出现:(NSNotification*)n
{
//键盘即将出现!
//与第一响应者打乒乓球,以确保其具有键盘外观方法:
[[UIApplication sharedApplication]sendAction:@selector(ts_ping:)//通过类别扩展添加
收件人:无//收件人:第一响应者
发件人:self/“发件人”
前景:无];
}
-(无效)ts_pong:(id)发件人
{
//发件人是第一个响应者。在本例中,碰巧是未记录的“UIWebBrowserView”。
//如果它没有自己的键盘外观方法,那么让我们添加一个:
如果(![sender respondsToSelector:@selector(键盘外观)])
{
方法m=class_getInstanceMethod([self class],@selector(keyboardAppearanceTemplateMethod));
IMP IMP=方法实现(m);
const char*typeEncoding=method_getTypeEncoding(m);
class_addMethod([sender class],@selector(键盘外观),imp,typeEncoding);
}
如果(![sender respondsToSelector:@selector(键盘类型)])
{
方法m1=class_getInstanceMethod([self class],@selector(keyboardTypeTemplateMethod));
IMP imp1=方法实现(m1);
const char*typeencoding 1=方法_getTypeEncoding(m1);
class_addMethod([sender class],@selector(keyboardType),imp1,typeEncoding1);
}
}
-(UIKeyboardAppearance)键盘外观模板方法
{
返回UIKeyboardAppearanceDark;
}
-(UIKeyboardType)keyboardTypeTemplateMethod
{
返回UIKeyboardTypeDecimalPad;
}
我可以得到的键盘外观是黑暗的,但不是我想要的键盘类型
到目前为止,我已经看到了其他线索和答案,但没有结果
在html字符串中尝试此选项
<input type="tel"></input>
或
这有一个新的插件:
有大量私有API将在app store提交中获得批准……我已经看到了一些API,但没有一个对我有效,请您帮助我找到一个有效的API。尝试搜索“Xcode UIWebView数字键盘小数点”@MSU_Bulldog现在没有私人API的工作了。@satheeshwaran运气好吗?Dude type=tel打开电话键盘,我特别想要十进制键。这就是问题的关键所在。仅供参考,我很久以前就尝试过这些。您是否尝试了第二个选项,使用pattern=“[0-9]”。是的,这将只显示字母数字键盘,但不允许使用字母。没有帮助。此方法使用不可见的文本视图,不会显示光标。我需要光标。仅供参考,我已经尝试过这种方法,无论如何,谢谢你的帮助!
<input type="text" pattern="[0-9]*"></input>