0

プログラムでいくつかの s を作成していUITextFieldますが、それらを委任しようとすると、次の警告が表示されます。

NAVPlanViewController *const __strong' を互換性のない型のパラメーターにid<UITextFieldDelegate>

textHeight = [[UITextField alloc] initWithFrame:CGRectMake(0, 120, 160, 40)];
[textHeight setDelegate:self];

そして、.c私のクラスに追加しまし@interface NAVPlanViewController : UIViewController <UITextViewDelegate>た。また、数字のみを受け入れるようにテキストフィールドを制限する必要があります。このコードでそれを行うことを考えましたが、UITextField確認Delegateできませんでした:

- (BOOL)textField:(UITextField *)textField 
        shouldChangeCharactersInRange:(NSRange)range 
                    replacementString:(NSString *)string {

    if (!string.length) {
            return YES;
    }

    if ([string rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] 
                                         invertedSet]].location != NSNotFound){
        //do something;
        return NO;
    }
4

2 に答える 2