UITextView inside UIScrollView is not the first responder

I have a UITextView on a view that becomes the first responder.

When I embed a UITextView inside a UIScrollView in the Interface Builder, the UITextView is no longer the first responder. I'm not sure what has changed?

I would like the UITextView to be the first responder.

- (void)viewDidLoad {
    [super viewDidLoad];
    [scrollView setContentSize:CGSizeMake(540,620)];
    composeTextView.delegate = self;    
    [composeTextView becomeFirstResponder];
}

      

0


a source to share


3 answers


This is my .h file:

#import <UIKit/UIKit.h>

@interface Untitled1ViewController : UIViewController <UITextFieldDelegate> {
    UIScrollView *scrollView;
    UITextField *composeTextView;
}

@property (nonatomic,retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic,retain) IBOutlet UITextField *composeTextView;

@end

      

this is my .m file:



#import "Untitled1ViewController.h"

@implementation Untitled1ViewController
@synthesize scrollView;
@synthesize composeTextView;
- (void)viewDidLoad {
    [super viewDidLoad];
    [scrollView setContentSize:CGSizeMake(540,620)];
    composeTextView.delegate = self;    
    [composeTextView becomeFirstResponder];


}

      

in IB, I've connected the following: a textField for the composeTextView, a scrollView for the scrollView, and a textField delegate for the owner of the file.

Try again and advise.

+1


a source


I did the same, added code and it works fine:



scrollView.contentSize = CGSizeMake(540,620);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
[composeTextView becomeFirstResponder];

      

0


a source


The text view accepts scroll events, and therefore scroll events are not propagated further down the responder chain. If you are not interested in scrolling the text view, disable scrolling in the textView (use the nib or scrollEnabled property), now the scrollView will start accepting scroll events.

0


a source







All Articles