来自UIViewController </uitextfielddelegate>的派生类中的<uitextfielddelegate>

时间:2013-01-05 04:14:53

标签: iphone ios uitextfield

提供以下派生类:

#import <UIKit/UIKit.h>

@interface NumberPadViewController : UIViewController {
    UIImage *numberPadDoneImageNormal;
    UIImage *numberPadDoneImageHighlighted;
    UIButton *numberPadDoneButton;
}

@property (nonatomic, retain) UIImage *numberPadDoneImageNormal;
@property (nonatomic, retain) UIImage *numberPadDoneImageHighlighted;
@property (nonatomic, retain) UIButton *numberPadDoneButton;

- (IBAction)numberPadDoneButton:(id)sender;

@end

在本课程中使用:

#import <UIKit/UIKit.h>
#import "NumberPadViewController.h"

@interface eatAddViewController : NumberPadViewController <UITextFieldDelegate> {
    UITextField *textAmount, *textTips;
}
@property (nonatomic, retain) IBOutlet UISegmentedControl *segAddType;
@property (nonatomic, retain) IBOutlet UITextField *textAmount;
@property (nonatomic, retain) IBOutlet UITextField *textDateTime;
@property (nonatomic, retain) IBOutlet UITextField *textExpenseType;
@property (nonatomic, retain) IBOutlet UITextField *textTips;
@property (nonatomic, retain) IBOutlet UITextField *textTotalAmount;

@end

使用“UITextFieldDelegate”会出现以下错误:

2013-01-04 22:54:32.916 ExpenseAccountTracking[39423:c07] -[UITextField object]: unrecognized selector sent to instance 0x8659f60
2013-01-04 22:54:32.916 ExpenseAccountTracking[39423:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField object]: unrecognized selector sent to instance 0x8659f60'
*** First throw call stack:
...

在“eatAddViewController”类中替换“UIViewController”的“NumberPadViewController”工作完美!

有任何线索吗?

我尝试将“UITextFieldDelegate”添加到“NumberPadViewController”,但没有任何运气!

这里是eatAddViewController.m代码:

#import "eatAddViewController.h"
#import "DateTimeInputView.h"
#import "PickerInputView .h"

@implementation eatAddViewController
@synthesize textAmount, textTips, textTotalAmount, formatter;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
// Do any additional setup after loading the view from its nib.
    formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = kCFNumberFormatterCurrencyStyle;

    DateTimeInputView *dateEntryView = [[DateTimeInputView alloc] init];
    self.textDateTime.inputView = dateEntryView;

    PickerInputView *expenseTypeView = [[PickerInputView alloc] init];
    expenseTypeView.pickerViewOptions = [[NSArray alloc] initWithObjects:NSLocalizedString(@"ExpenseBreakfast", nil), NSLocalizedString(@"ExpenseLunch", nil),
                                         NSLocalizedString(@"ExpenseDiner", nil), NSLocalizedString(@"ExpenseHotel", nil), NSLocalizedString(@"ExpenseOthers",nil), nil];
    self.textExpenseType.inputView = expenseTypeView;
    self.title = NSLocalizedString(@"Add", nil);

    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITextFieldDelegate

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == self.textDateTime)
    {
    }
}

@end

1 个答案:

答案 0 :(得分:0)

谢谢 Phillip 。我是Xcode的新手(3天;-)并且不熟悉这个。问题出在我从网络(NumberPadViewController)剪下的一些代码中。

- (void)textFieldDidBeginEditing:(NSNotification *)note {
//    [self updateKeyboardButtonFor:[note object]];
    [self updateKeyboardButtonFor:[self findFirstResponderTextField]];
}

没有<UITextFieldDelegate>,此函数未被调用。所以问题在之前就已隐藏。