给出以下派生类:
#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”类中将“NumberPadViewController”替换为“UIViewController”可以完美地工作!
有什么线索吗?
我尝试将“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