2012-11-12 17 views
1

我有文本字段中的UITableView的自定義單元格。我泰伯維是的MainView的下部,所以當我在CustomCell鍵盤,點擊文本字段出現哪些隱藏下面的圖片我textfield.My顯示我的問題如何在UITableview的CustomCell中單擊UITextField時移動查看?

enter image description here

在這裏,我有一個代碼,當我在MainView中有UITextField時可以工作。請編輯下面的代碼Beacuse我希望整個視圖動畫,當我點擊UITextfield時。

-(void)textFieldDidBeginEditing:(UITextField *)textField { 

if (textField.tag > 0) { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-165.0, 
           self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} 

    } 
-(void)textresign{ 

[[self.view viewWithTag:1]resignFirstResponder]; 
    } 
-(void)textFieldDidEndEditing:(UITextField *)textField {   
if (textField.tag > 0) { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view .frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+165.0, 
            self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} 

    } 

但我我以前不知道如何修復它爲我的自定義單元格UITextField.Any幫助將appriated。

回答

5

這裏是代碼,只需要改變代碼點點以下方法

-(void)textFieldDidBeginEditing:(UITextField *)textField 
{ 

    if (textField.tag > 0) 
    { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDuration:0.5]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-165.0, 
            self.view.frame.size.width, self.view.frame.size.height); 
     [UIView commitAnimations]; 
    } 
} 

使用了重新定位鍵盤辭職,而不是textFieldDidEndEditing上的視圖。

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 

    if (textField.tag > 0) 
    { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDuration:0.5]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     self.view .frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+165.0, 
             self.view.frame.size.width, self.view.frame.size.height); 
     [UIView commitAnimations]; 

    } 
    [textField resignFirstResponder]; 
    return YES; 
} 

使用以下方法強制到委託設置爲文本字段。

我希望你能得到解決方案。

+0

感謝它的工作原理,但移動後視圖永不停止。 – jamil

+0

@SHAZAD調試並檢查此'textFieldShouldReturn'方法,無論您何時嘗試退出鍵盤,都會調用此方法。 – Kamarshad

+0

得到它感謝它現在工作正常。 – jamil

相關問題