簡體   English   中英

以編程方式專注於UITextView無法正常工作

[英]Programmatically focus on UITextView is not working

在關閉帖子重復之前,請相信我,我正在搜索2天,但仍然一無所獲。 我會盡量清楚:

我有一個帶有textview的視圖。我需要自動將焦點設置在textview上,以便出現鍵盤不適。

PostView.h

@interface PostView : UIViewController{
UITextView *txtPesto;
}
@property (nonatomic,retain) IBOutlet UITextView *txtPesto;
@end

PostView.m

#import "PostView.h"
@implementation PostView
@synthesize txtPesto;

- (void)viewDidLoad
{

    [super viewDidLoad];
   [txtPesto becomeFirstResponder];
}

由於某些非常奇怪的原因,盡管我嘗試了許多示例和不同的方法,但是我的代碼無法正常工作。 有什么幫助嗎?

我的評論(針對結束的問題)回答:右鍵單擊textView,然后單擊“新的引用出口”,這可能會有所幫助嗎?

您在.h文件中兩次聲明txtPesto

@interface PostView : UIViewController{
    UITextView *txtPesto;
}
@property (nonatomic,retain) IBOutlet UITextView *txtPesto;
@end

當您將其聲明為屬性時,無需再次進行操作。 因此,刪除多余的聲明,並使用以下代碼:

@interface PostView : UIViewController

@property (nonatomic,retain) IBOutlet UITextView *txtPesto;

@end

我看不到becomeFirstResponder任何其他原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM