元の質問: 3 つの UITextField (nameField、locationField、および discriptionField) があります。if ステートメント トリガーを discriptionField にのみ設定する必要がありますが、私が試した方法 (以下で構成) では、3 つのテキスト フィールドすべてが setViewMovedUp を実行します。if([sender isEqual: discriptionField]) も試しましたが、同じ問題が発生しています。3つのテキストフィールドすべてがメソッドを実行します。
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if (sender == discriptionField)
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
}
私の解決策: 初歩的なミスです。気づかずに別のメソッドから同じメソッドを呼び出していました。おそらく問題を解決するための悪い方法ですが、ここに私の解決策があります。
BOOL onlyDiscription = NO;
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:discriptionField])
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
onlyDiscription = YES;
}
}
}
-(void)keyboardWillShow {
if (onlyDiscription) {
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
}
-(void)keyboardWillHide {
if (onlyDiscription) {
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
con = YES;
[self setViewMovedUp:NO];
}
onlyDiscription = NO;
}
}