2

こんにちは、スクロールして 1 つのテキスト ボックスを非常に簡単に操作できますが、10 個のテキスト ボックスを追加し、リンゴのドキュメントのコードを使用すると、10 個のフィールドのいずれかのタッチを委任してビューをスクロールする方法がわかりません。 、問題の textField に activeField を接続する方法がわかりません。それが私が落ち込んでいるところだと思います、そして答えは委任にあります

@interface ImmyViewController ()

@end

@implementation ImmyViewController
@synthesize activeField;
@synthesize scrollView;
@synthesize text1;
@synthesize text2;
@synthesize text3;
@synthesize text4; 
@synthesize text5;
@synthesize text6;
@synthesize text7;
@synthesize text8;
@synthesize text9;
@synthesize text10;

- (void)viewDidLoad
{
    [super viewDidLoad];

    text1.delegate =self;
    text2.delegate =self;
    text3.delegate =self;
    text4.delegate =self;
    text5.delegate =self;
    text6.delegate =self;
    text7.delegate =self;
    text8.delegate =self;
    text9.delegate =self;
    activeField.delegate=self;

    text10.delegate =self;

// Do any additional setup after loading the view, typically from a nib.
//---set the viewable frame of the scroll view---
    scrollView.frame = CGRectMake(0, 0, 320, 460);

//---set the content size of the scroll view---
    [scrollView setContentSize:CGSizeMake(320, 833)];

}

// このメソッドをビュー コントローラのセットアップ コードのどこかで呼び出します。- (void)registerForKeyboardNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillBeHidden:)
                                             name:UIKeyboardWillHideNotification object:nil];

}

// UIKeyboardDidShowNotification が送信されたときに呼び出されます。- (void)keyboardWasShown:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;

// If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
    CGPoint scrollPoint = CGPointMake(0.0, text10.frame.origin.y-kbSize.height);
    [scrollView setContentOffset:scrollPoint animated:YES];
}

}

// UIKeyboardWillHideNotification が送信されたときに呼び出されます - (void)keyboardWillBeHidden:(NSNotification*)aNotification {

    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
 }

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    activeField = textField;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    activeField = nil;
}
4

1 に答える 1