次の派生クラスを指定します。
#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