我在视图上有一个UITextView,它成为第一个响应者。
当我在界面生成器中的UIScrollView中嵌入UITextView时,UITextView不再是第一个响应者。我不确定发生了什么变化?
我希望UITextView成为第一个响应者。
- (void)viewDidLoad {
[super viewDidLoad];
[scrollView setContentSize:CGSizeMake(540,620)];
composeTextView.delegate = self;
[composeTextView becomeFirstResponder];
}
答案 0 :(得分:1)
这是我的.h文件:
#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
这是我的.m文件:
#import "Untitled1ViewController.h"
@implementation Untitled1ViewController
@synthesize scrollView;
@synthesize composeTextView;
- (void)viewDidLoad {
[super viewDidLoad];
[scrollView setContentSize:CGSizeMake(540,620)];
composeTextView.delegate = self;
[composeTextView becomeFirstResponder];
}
在IB中,我连接了以下内容:
textField to composeTextView
scrollView to scrollView
并且textField委托给文件的所有者。
再试一次并提出建议。
答案 1 :(得分:0)
我也做了同样的事情,添加了一些代码并且工作正常:
scrollView.contentSize = CGSizeMake(540,620);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
[composeTextView becomeFirstResponder];
答案 2 :(得分:0)
文本视图采用滚动事件,因此滚动事件不会在其响应程序链中进一步传递。如果您对滚动文本视图不感兴趣,请禁用textView中的滚动(使用nib或scrollEnabled属性),现在,scrollView将开始播放滚动事件。