UITextField键盘无法输入任何内容 [英] UITextField keyboard can't type anything

查看:71
本文介绍了UITextField键盘无法输入任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

加载一个xib文件作为UIView,然后我从一个Xib文件得到一个UITextField(它只是一个包含文本字段和按钮的视图).但是,当应用程序启动并且出现该文本字段时.我不能在此UITextField上键入任何字母.但是将文本粘贴到该UITextField是可以的.为什么?这是我添加的代码

load a xib file as a UIView, and I got a UITextField form a Xib file(it just a view that contains textfield and button). But when the app launched and that textfield comes up. i cannot type any alphabet on this UITextField. But paste a text to that UITextField was OK. Why? Here is my adding code

-(IBAction)showSheet{    
    UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@"LoginViewComp" owner:self options:NULL] lastObject];    
     [myView setFrame:CGRectMake(0, 44, 320, 400)];

    UIButton *btn1 = (UIButton *)[myView viewWithTag:101];
    UITextField *field = (UITextField *)[myView viewWithTag:102];
    UILabel *lbl = (UILabel *)[myView viewWithTag:103];    

    [field setEnabled:YES];

    [btn1 addTarget:self action:@selector(testBtn1) forControlEvents:UIControlEventTouchUpInside];

    DTActionSheet *sheet = [[DTActionSheet alloc] initWithContentView:myView sheetTitle:@"Demo"];
    [sheet showInView:self.view];
    [sheet setUserInteractionEnabled:YES];
}

-(void)testBtn1{
    NSLog(@"btn1 touch up inside");     
}
@end

DTActionSheet.m

DTActionSheet.m

@interface DTActionSheet()
@property (nonatomic,strong) UIView* contentView;
@property (nonatomic,strong) UIToolbar* toolBar;
@end

@implementation DTActionSheet
@synthesize contentView=_contentView;
@synthesize toolBar=_toolBar;

-(id)initWithContentView:(UIView*)contentView sheetTitle:(NSString*)title;
{
    self = [super init];
    if (self) 
    {
        _contentView = contentView;
        int btnnum = (contentView.frame.size.height-5)/50; // (height+44-20-25)/50
        for(int i=0; i<btnnum; i++)
        {
            [self addButtonWithTitle:@" "];
        }
        _toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
        _toolBar.barStyle = UIBarStyleBlackOpaque;

        UIBarButtonItem *titleButton = [[UIBarButtonItem alloc] initWithTitle:title 
                                                                        style:UIBarButtonItemStylePlain 
                                                                       target:nil 
                                                                       action:nil];

        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                                                                        style:UIBarButtonItemStyleDone 
                                                                       target:self
                                                                       action:@selector(done)];

        UIBarButtonItem *leftButton  = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" 
                                                                        style:UIBarButtonItemStyleBordered 
                                                                       target:self 
                                                                       action:@selector(cancel)];

        UIBarButtonItem *fixedButton  = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                                                                                      target:nil 
                                                                                      action:nil];

        [_toolBar setItems: [NSArray arrayWithObjects:leftButton,fixedButton,titleButton,fixedButton,rightButton,nil]];

        [self addSubview:_toolBar];
        [self addSubview:_contentView];
    }
    return self;
}

-(void)done
{
    [self dismissWithClickedButtonIndex:0 animated:YES];
}
-(void)cancel
{
    [self dismissWithClickedButtonIndex:0 animated:YES];
}
@end

嘿,大家有什么主意吗?

Hey, guys, have any idea?

推荐答案

尝试使用UIKeyInput协议参考进行输入- http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html

try using UIKeyInput Protocol Reference for input -- http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html

确保使用其委托..

这篇关于UITextField键盘无法输入任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆