简体   繁体   中英

UITextView inside UIScrollView is not First Responder

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

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

I would like the UITextView to become the first responder.

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

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: textField to composeTextView scrollView to scrollView and the textField delegate to the file's owner.

Try again and advise.

I've done the same, added some code and it works OK:

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

The text view takes scroll events and hence the scroll events are not passed on further in its responder chain. If you are not interested in scrolling the text view, disable the scrolling in textView (use nib or scrollEnabled property), now, scrollView will start taking scroll events.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM