我在tableview单元格中有一个文本字段,我想分配一个自定义输入键盘。我可以让键盘显示出来,但似乎没有连接相应的控制器类。当我按任意按钮时,出现EXC_BAD_ACCESS错误或“无法识别的选择器”错误。
以下是将tableview单元格的文本字段绑定到自定义输入键盘的代码
CustomNumberPadViewController *calcKeyboard = [[CustomNumberPadViewController alloc] initWithNibName:@"CustomNumberPadView" bundle:nil];
calcKeyboard.equationViewController = self;
cell.variableValue.inputView = calcKeyboard.view;
我有关于calkKeyboard按钮的动作方法,当我按下按钮时,这些方法没有被调用。我甚至实例化了一个“viewWillAppear”方法,当键盘出现时也没有调用它。
我检查了numberpad的类,它连接到CustomNumberPadViewController,它包含上面提到的方法。
以下是我的CustomNumberPadViewController的代码:
#import <UIKit/UIKit.h>
#import "EquationViewController.h"
@class EquationViewController;
@interface CustomNumberPadViewController : UIViewController <UITextFieldDelegate>{
EquationViewController *equationViewController;
}
@property (nonatomic, strong) EquationViewController *equationViewController;
-(IBAction)buttonPressed:(id)sender;
-(IBAction)buttonDonePressed:(id)sender;
-(IBAction)buttonDelPressed:(id)sender;
@end
并且相关的实现(为了简洁起见,我已经删除了操作方法的内容,只是离开了我的调试日志):
#import "CustomNumberPadViewController.h"
#import "VariableCellController.h"
@implementation CustomNumberPadViewController
@synthesize equationViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
-(void) viewWillAppear:(BOOL)animated
{
UIColor *backgroundPatern = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"calculatorBackground.png"]];
self.view.backgroundColor = backgroundPatern;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark - Action Methods
-(IBAction)buttonPressed:(id)sender{
NSLog(@"61-CNPVC");
}
-(IBAction)buttonDonePressed:(id)sender{
NSLog(@"117-CNPVC");
}
-(IBAction)buttonDelPressed:(id)sender{
NSLog(@"125-CNPVC");
}
@end
答案 0 :(得分:2)
我认为您需要保留CustomNumberPadViewController,方法是将其添加到addChildViewController
或将其分配给属性。
尝试使用zombies enabled进行调试。