Reputation: 796
Before closing the post as duplicate,believe me,i am searching this for 2 days but still nothing. I will try to be as clear as possible:
I have a view with a textview.I need to set focus automatically on the textview so the keyboard ill appear.
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];
}
For some very strange reason my code is not working,although i have tried many samples and different approaches. Any help?
Upvotes: 0
Views: 660
Reputation: 3545
Answer from my comment (for closing question): Right click on textView, and "new referncing outlet", maybe that will be helpful?
Upvotes: 2
Reputation: 11004
You are declaring txtPesto
twice in your .h file:
@interface PostView : UIViewController{
UITextView *txtPesto;
}
@property (nonatomic,retain) IBOutlet UITextView *txtPesto;
@end
When you declare it as a property, you don't need to do it again. So remove the extra declaration, and just use this:
@interface PostView : UIViewController
@property (nonatomic,retain) IBOutlet UITextView *txtPesto;
@end
I don't see any other reason that becomeFirstResponder
wouldn't work.
Upvotes: 1