【问题标题】:Why doesn't the textfield code work for Xcode 8 Obj-C?为什么文本字段代码不适用于 Xcode 8 Obj-C?
【发布时间】:2017-09-11 06:28:54
【问题描述】:

ViewController.h

@interface ViewController : UIViewController{

IBOutlet UITextField *Signup;
IBOutlet UITextField *Login;

}
@property(nonatomic, retain)IBOutlet UITextField *Signup;
@property(nonatomic, retain)IBOutlet UITextField *Login;

-(IBAction)TYPE:(id)sender;

ViewController.m

@synthesize Signup;
@synthesize Login;

-(IBAction)TYPE:(id)sender{
[Signup resignFirstResponder];
[Login resignFirstResponder];
}

在模拟器中单击文本字段时,我收到以下错误消息:

2017-04-14 18:43:52.616362 Prototype1[3075:119579] [MC] systemgroup.com.apple.configurationprofiles 路径的系统组容器是 /Users/robertstoley/Library/Developer/CoreSimulator/Devices/09556F3B- A7BC-4DF2-95EB-C3C13B6F39EA/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2017-04-14 18:43:52.640402 Prototype1 [3075:119579] [MC] 从私人有效用户设置中读取。 2017-04-14 18:43:52.727 Prototype1[3075:119579] 找不到支持 iPhone-PortraitChoco-NumberPad 键盘类型 4 的键盘;使用 1316927560_PortraitChoco_iPhone-Simple-Pad_Default 2017-04-14 18:43:53.607676 Prototype1 [3075:119579] [Common] _BSMachError:端口 7403; (os/kern) 无效能力 (0x14) “无法插入 COPY_SEND” 2017-04-14 18:43:53.608246 Prototype1 [3075:119579] [Common] _BSMachError: 端口 7403; (os/kern) 无效名称 (0xf) "无法解除分配发送权限"

我已经 2 年没有使用 Xcode 了,但是同样的代码当时运行良好,为什么它不适用于 Xcode 8、iOS 10?

【问题讨论】:

    标签: ios uitextfield xcode8 textfield


    【解决方案1】:

    Xcode 8 的模拟器相当冗长。这些消息没有什么特别的意义。

    -- 顺便说一句--

    您的代码是用一种 非常 旧的风格编写的,不再是最佳实践。更好的是:

    @interface ViewController : UIViewController
    // It's no longer necessary to have your properties between { and }
    
    @property (nonatomic, weak) IBOutlet UITextField *signup;
    @property (nonatomic, weak) IBOutlet UITextField *login;
    // IBOutlets should be weak, other properties should be weak or strong for objects, or assign for structs and values.
    @end
    
    
    @implementation ViewController
    
    // You don't have to synthesize your properties anymore.
    
    - (IBAction)type:(id)sender {
        [self.signup resignFirstResponder];
        [_login resignFirstResponder];
        // but you do have to either use self. or underscore to refer to them.
    }
    
    @end
    

    【讨论】:

    • 键盘根本不显示。如何让键盘显示出来?
    • 啊,这与您的 xib 文件或情节提要有关。鉴于您的代码看起来有多旧,我猜您正在处理 xib 文件。
    • 我正在使用情节提要。有什么问题?我如何解决它?我已经 2 年没有编码了。如果有帮助的话,我刚回来。
    • 发布您的故事板的屏幕截图。每个文本字段的右侧面板。
    • 谢谢,但我已经想通了。你是对的。这是一个故事板问题。我必须打开模拟器>硬件>切换软件。然后键盘开始正常工作。
    猜你喜欢
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 2019-11-20
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    相关资源
    最近更新 更多