2 sinat 27895061 sinat_27895061 于 2016.09.18 11:37 提问

[oc]已经设置了uitextfield,但是tap它并不弹出键盘怎么办?

已经设置了firstresponder,cmd+shift+k或者cmd+k也不管用
哪位老师帮我看看怎么回事?
#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
#pragma mark - Table view management

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Because this table view only has one section, // the number of rows in it is equal to the number // of items in the tasks array return [self.tasks count]; }
  • (UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    // To improve performance, this method first checks
    // for an existing cell object that we can reuse
    // If there isn't one, then a new cell is created
    UITableViewCell *c = [self.taskTable dequeueReusableCellWithIdentifier:@"Cell"];
    // Then we (re)configure the cell based on the model object,
    // in this case the tasks array, ...
    NSString *item = [self.tasks objectAtIndex:indexPath.row];
    c.textLabel.text = item;
    // ... and hand the properly configured cell back to the table view
    return c;
    }
    #pragma mark - Application delegate callbacks

  • (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //create an empty array to get us start
    self.tasks = [NSMutableArray array];
    // Create and configure the UIWindow instance
    // A CGRect is a struct with an origin (x,y) and a size (width,height)
    CGRect winFrame = [[UIScreen mainScreen] bounds];
    UIWindow *theWindow = [[UIWindow alloc] initWithFrame:winFrame];
    self.window = theWindow;
    UIViewController
    window = [[UIViewController alloc]initWithNibName:nil bundle:nil];

    self.window.rootViewController = window;
    // Define the frame rectangles of the three UI elements
    // CGRectMake() creates a CGRect from (x, y, width, height)
    CGRect tableFrame = CGRectMake(0, 80, winFrame.size.width,
    winFrame.size.height - 100);
    CGRect fieldFrame = CGRectMake(20, 40, 270, 31);
    CGRect buttonFrame = CGRectMake(298, 40, 72, 31);
    // Create and configure the UITableView instance
    self.taskTable = [[UITableView alloc] initWithFrame:tableFrame
    style:UITableViewStylePlain];
    self.taskTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    // Make the BNRAppDelegate the table view's dataSource
    self.taskTable.dataSource = self;
    // Tell the table view which class to instantiate whenever it
    // needs to create a new cell
    [self.taskTable registerClass:[UITableViewCell class]
    forCellReuseIdentifier:@"Cell"];
    // Create and configure the UITextField instance where new tasks will be entered
    self.taskField = [[UITextField alloc] initWithFrame:fieldFrame];
    self.taskField.borderStyle = UITextBorderStyleRoundedRect;
    self.taskField.placeholder = @" Type a task, tap Insert";

    // Create and configure the UIButton instance
    self.insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.insertButton.frame = buttonFrame;
    // Give the button a title
    [self.insertButton setTitle:@"Insert"
    forState:UIControlStateNormal];
    // Add our three UI elements to the window
    [self.window addSubview:self.taskTable];
    [self.window addSubview:self.taskField];
    [self.window addSubview:self.insertButton];
    // Finalize the window and put it on the screen
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    // Set the target and action for the Insert button
    [self.insertButton addTarget:self
    action:@selector(addTask:)
    forControlEvents:UIControlEventTouchUpInside];
    return YES;
    }

  • (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

  • (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

  • (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

  • (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

  • (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    #pragma mark - Actions

  • (void)addTask:(id)sender
    {
    //get the task
    NSString *text = [self.taskField text];
    //quit here if the taskField is empty
    if([text length] == 0){
    return;
    }
    // Add it to the working array
    [self.tasks addObject:text];
    // Refresh the table so that the new item shows up
    [self.taskTable reloadData];
    //clear out the text field
    [self.taskField setText:@""];
    //dismiss the keyboard
    [self.taskField resignFirstResponder];
    }

@end

2个回答

zqbnqsdsmd
zqbnqsdsmd   2016.09.28 01:18
qq_34821861
qq_34821861   2016.10.08 18:03

没有看到遵守协议 设置代理

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
点击UITextField不弹出键盘
如果用Xcode6创建工程,用模拟器运行程序,点击UITextFiled不弹出键盘可以这样操作: 点模拟器  然后 点  hardware   然后选keyboard   然后里面的第3个选项打勾
iOS UITextField 获得焦点后,阻止弹出键盘事件
iOS 时间选择器用UITextField记录选择的时间,有个问题就是,如何阻止默认的加载软键盘时间。我在网上找了好久也没有这方面的解决方案。后来我看到一片关于用iOS通告技术自定义切入想要执行的方法,最后实现了该问题的解决方案。不说了,直接上代码: 1.首先页面实现UITextFieldDelegate,并将self.delegate =self; 然后在.m页面
OC textField键盘弹起事件
OC textField键盘弹起事件 经常用到点击textFiled时弹起键盘,然后 textField工具条也要随之上升,自己做了个简单的例子 1. 监听键盘弹起收回事件 //监听键盘弹出事件 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) n
UITextField输入框响应键盘的弹出做高度的自适应
iOS开发中,注册登录页面可以说是必不可少的,我们经常遇到的问题无非就是键盘弹出之后遮住了输入框。所以我们要在键盘弹出或收回的同时调节输入框的高度,进而解决键盘遮住输入框的问题!!!
UItextField只获取焦点,不显示系统键盘
#pragma textDelegate -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{     //获取焦点后清空内容 //    textField.text = @"";     textField.inputView=[[UIView alloc]initWithFrame:CGRectZero];  
iOS:UITextField中键盘的关闭
在iOS 程序中当想要在文本框中输入数据,轻触文本框会打开键盘。对于 iPad 程序,其键盘有一个按钮可以用来关闭键盘,但是 iPhone 程序中的键盘却没有这样的按钮,不过我们可以采取一些方法关闭它。例如,我们可以实现按下 Rerun (有时也是 Done、Research等)键关闭键盘,或者,更人性化的,轻触背景关闭键盘。 1、直接用控件实现按下Return
ios开发之uitextview及uitextfield获得焦点时弹出的自定义键盘及键盘上面的附加view设置
转自http://www.dnetzj.com/Content/420.html 在ios开发中有时候想让文本框获得焦点的时候弹出的不是键盘而是自定义的东西,这个可以通过改变textfield或者textview的inputView来设置;但是要是想在普通键盘上面加一个自定义的view可以通过改变textfield或者textview的inputAccessoryView属性来设置。例如:
iOS UITextField输入框随键盘弹出界面上移
//点击输入框界面跟随键盘上移 - (void)textFieldDidBeginEditing:(UITextField *)textField {          CGRect frame = textField.frame;     int offSet = frame.origin.y + 70 - (self.view.frame.size.height
iOS 键盘弹出遮挡UITextField解决方法
//增加监听,当键退出时收出消息     [[NSNotificationCenter defaultCenter] addObserver:self                                              selector:@selector(keyboardWillHide:)                               
iOS中UITextField不弹起输入键盘,弹起自定义的菜单
在做项目的时候有时候我们用到UITextField,但是我们再输入的时候不想弹起系统的键盘,我们想让他们弹起我们自定义的View,这时我们就要将UITextField的inputView指向我们自定义的View 1.将UITextField遵守UITextFieldDelegate协议. 2.重写-(BOOL)textFieldShouldBeginEditing:(UITextField *