1
我構建了一個應用程序,當textview被填充時,鍵盤會彈出並允許您鍵入。如果我決定不想使用鍵盤,我可以點擊背景視圖控制器,它會掉下來。現在,我添加了一個滾動視圖。一切工作正常,但我無法獲得連接的操作,並在觸摸Textview外部時使鍵盤掉落。 (我不能在Xcode中製作自定義視圖控制器)IOS UIScrollview不允許鍵盤在觸摸屏幕時關閉
有沒有人有任何修復?
預先感謝您!
@interface ViewController()
@property (weak, nonatomic) IBOutlet UITextField *actionField;
@property (weak, nonatomic) IBOutlet UITextField *impactField;
@property (weak, nonatomic) IBOutlet UITextField *resultField;
@end
@implementation ViewController
- (NSString *)dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager]
fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc]
initWithContentsOfFile:filePath];
for (int i = 0; i < 3; i++) {
UITextField *theField = self.lineFields [i];
theField.text = array [i];
}
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:app];
}
- (void)applicationWillResignActive:
(NSNotification *)notification
{
NSString *filePath = [self
dataFilePath];
NSArray *array = [self.lineFields valueForKey:@"text"];
[array writeToFile:filePath atomically:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)backgroundTap: (id)sender {
[self.actionField resignFirstResponder];
[self.impactField resignFirstResponder];
[self.resultField resignFirstResponder];
}
您可以發佈您的代碼? – Raptor 2015-03-03 04:03:15
感謝您尋找猛禽。我沒有添加代碼,因爲我認爲這是一個Xcode連接問題 – mhinton11 2015-03-03 05:16:13
據我所知,touchbegan函數在滾動視圖中不起作用。每當用戶滾動時都會更好,您可以關閉鍵盤。否則用鍵盤添加一個工具欄按鈕(關閉)。 – 2015-03-03 05:35:00