简体   繁体   English

为什么文本字段代码对Xcode 8 Obj-C不起作用?

[英]Why doesn't the textfield code work for Xcode 8 Obj-C?

ViewController.h 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 ViewController.m

@synthesize Signup;
@synthesize Login;

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

In Simulator when I click on the textfield I get the following error message: 在模拟器中,当我单击文本字段时,出现以下错误消息:

2017-04-14 18:43:52.616362 Prototype1[3075:119579] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /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] Reading from private effective user settings. 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] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; 2017-04-14 18:43:52.727 Prototype1 [3075:119579]找不到支持键盘iPhone-PortraitChoco-NumberPad的类型4的键盘。 using 1316927560_PortraitChoco_iPhone-Simple-Pad_Default 2017-04-14 18:43:53.607676 Prototype1[3075:119579] [Common] _BSMachError: port 7403; 使用1316927560_PortraitChoco_iPhone-Simple-Pad_Default 2017-04-14 18:43:53.607676 Prototype1 [3075:119579] [Common] _BSMachError:端口7403; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND" 2017-04-14 18:43:53.608246 Prototype1[3075:119579] [Common] _BSMachError: port 7403; (os / kern)无效功能(0x14)“无法插入COPY_SEND” 2017-04-14 18:43:53.608246 Prototype1 [3075:119579] [Common] _BSMachError:端口7403; (os/kern) invalid name (0xf) "Unable to deallocate send right" (os / kern)无效名称(0xf)“无法取消分配发送权限”

I haven't used Xcode in 2 years, but this same code worked fine then, why doesn't it work for Xcode 8, iOS 10? 我已经有两年没有使用Xcode了,但是同样的代码可以正常工作,为什么它不能用于Xcode 8,iOS 10?

The simulator for Xcode 8 is quite verbose. Xcode 8的模拟器非常冗长。 Those messages don't mean anything special. 这些消息并不意味着什么特别。

-- BTW -- -顺便说一句-

Your code is written in a very old style that isn't best practice anymore. 您的代码以老的风格编写,现在不再是最佳实践。 Better is: 更好的是:

@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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM