gpt4 book ai didi

ios - 在 iOS 中摆脱键盘

转载 作者:行者123 更新时间:2023-11-29 02:21:35 25 4
gpt4 key购买 nike

当我在 iOS 中按下返回键时,我无法让我的键盘消失。我在头文件中设置了 self.textField.delegate = self;我已经实现了以下内容:

-(BOOL)textFieldShouldReturn:UITextField *)textField {
[textField resignFirstResponder];
}

起初当我按下 enter 时它不会做任何事情,但是现在,在使用 Connections Inspector 将 Did End on Exit 连接到 View Controller 之后,我得到一个 NSInvalidArgumentException 原因 -[ViewController dismissKeyboard:]:无法识别的选择器发送到实例 0x155e10620。

有什么想法吗?我正在使用 Xcode 6.1。我将 Did End On Exit 连接到 textField 所在的 View Controller ,当我释放连接时,出现一个小按钮,上面写着 originText,我选择了它,因为它是唯一的选项。

这是我的代码(缩写)-

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreBluetooth/CoreBluetooth.h>


@interface ViewController : UIViewController <CBCentralManagerDelegate, CBPeripheralDelegate, UITextFieldDelegate>

@property (strong, nonatomic) CBCentralManager *centralManager;

@property (strong, nonatomic) CBPeripheral *discoveredPerepheral;
@property (strong) CBUUID *myServiceUUID;
@property (strong, nonatomic) NSMutableData *data;

@property (strong, nonatomic) IBOutlet UITextField *originText;
@property (strong, nonatomic) IBOutlet UITextField *destText;
@property (strong, nonatomic) AVSpeechSynthesizer *synth;
@property (strong, nonatomic) AVSpeechUtterance *utter;
@property (weak, nonatomic) IBOutlet UILabel *charLabel;

@property (weak, nonatomic) IBOutlet UILabel *isConnected;

@property (weak, nonatomic) IBOutlet UILabel *myPeripherals;

@property (weak, nonatomic) IBOutlet UILabel *aLabel;
- (IBAction)originText:(id)sender;

- (BOOL)textFieldShouldReturn:(UITextField *)textField;
- (void)textFieldDidEndEditing:(UITextField *)textField;


@end



#import "ViewController.h"

@interface ViewController ()

@property int myInt;

@end

@implementation ViewController

bool isConnected = NO;
CBCharacteristic *originChar;
CBUUID *originUUID;
NSString *const tempUUID = @"0499F5DB-DDC6-4BEF-B551-EB69F9254BB9";

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad {

self.centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil options:nil];
_data = [[NSMutableData alloc]init];
originUUID = [CBUUID UUIDWithString:@"0499F5DB-DDC6-4BEF-B551-EB69F9254BB9"];
_myServiceUUID = [CBUUID UUIDWithString:@"16055ED2-606D-47D4-B4C0-8F6BFC903DAB"];
_synth = [[AVSpeechSynthesizer alloc] init];
[_originText setDelegate:self];
[_destText setDelegate:self];
_originText.returnKeyType = UIReturnKeyGo;

}...

- (IBAction)originText:(id)sender {
if (isConnected) {
NSData *dataToWrite = [_originText.text dataUsingEncoding:NSUTF8StringEncoding];
//[_discoveredPerepheral writeValue:dataToWrite forCharacteristic:originChar type:CBCharacteristicWriteWithResponse];
NSLog(@"Data Written.");
}
NSLog(@"Disconnected.");
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"HEy Hey");
[textField resignFirstResponder];
return NO;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
}

@end

最佳答案

您在 textFieldSouldReturn 中有错字。因此,此委托(delegate)方法从未被调用。

关于ios - 在 iOS 中摆脱键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28078499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com