![](/img/trans.png)
[英]Dynamic Text Input from a UIButton on Custom Keyboard Extension in ios
[英]Check if input text is empty in custom keyboard for iOS 8
我正在為iOS 8開發自定義鍵盤,我想檢查輸入文本是否為空,以啟用或禁用返回鍵按鈕(如果需要)( self.textDocumentProxy.enablesReturnKeyAutomatically == YES
)。
到目前為止,這是我所做的:
- (void)textDidChange:(id<UITextInput>)textInput
{
NSString *inputText = [self.textDocumentProxy.documentContextBeforeInput stringByAppendingString:self.textDocumentProxy.documentContextAfterInput];
if (self.textDocumentProxy.enablesReturnKeyAutomatically)
{
self.returnButton.enabled = !(inputText.length == 0);
}
else
{
self.returnButton.enabled = YES;
}
}
但是,如果“自動啟用返回鍵”為ON,則即使輸入文本不為空,返回按鈕也始終處於禁用狀態。 檢查輸入文本是否為空的正確方法是什么? 謝謝。
試試這個,再次測試
在以下執行deleteBackward操作的功能中禁用返回鍵
- (IBAction)returnBackSpacePressed
{
[self.textDocumentProxy deleteBackward];
if(self.textDocumentProxy.documentContextBeforeInput.length-1 == 0)
{
[self.textDocumentProxy insertText:@"Now disable your return key"];
// Here your inputTest is now empty
}
}
在您插入insertTest時結束啟用返回鍵
- (void)putChar:(NSString *)charactor
{
[self.textDocumentProxy insertText:charactor];
// enable your return key here again, because now your inputText is not empty
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.