2012-03-15 47 views
0

我在UITextView上有一個圖像重疊。我想在用戶開始觸摸文本視圖並開始編輯時隱藏圖像。我應該使用哪些代碼? 我試過下面的代碼,但不起作用。開始編輯textview時隱藏圖像

-(IBAction)textViewDidBeginEditing:(UITextView *)textView{ 
    img1.hidden=YES; 
} 
+1

你正確設置的UITextView的代表? – lawicko 2012-03-15 17:18:18

回答

2

它應該是:

- (void)textViewDidBeginEditing:(UITextView *)textView{ 
img1.hidden=YES; 
} 

另外,不要忘記實現以下,所以當TextView的停止編輯,你可以取消隱藏它。

- (void)textViewDidEndEditing:(UITextView *)textView{ 
    img1.hidden=NO; 
} 

您還必須確保您的代理的設置是否正確,如:

myTextViewName.delegate = self; //This should probably go in the viewDidLoad section. 

<UITextViewDelegate> //This should go after the @interface ViewController : UIViewController (or similar) in your headers file (.h). So it should look something like @interface ViewController : UIViewController <UITextViewDelegate> 
1

你要做這樣的

- (void)textViewDidBeginEditing:(UITextView *)textView{ 
    img1.hidden=YES; 

} 

這將隱藏圖像視圖

- (void)textViewDidEndEditing:(UITextView *)textView{ 
     img1.hidden=NO; 
} 

這將顯示圖像編輯完成時。