【发布时间】:2012-03-08 19:16:36
【问题描述】:
我在表格视图单元格中有一个文本字段,我想分配一个自定义输入键盘。我可以让键盘显示出来,但似乎没有连接相应的控制器类。当我按下任何按钮时,我会收到 EXC_BAD_ACCESS 错误或“无法识别的选择器”错误。
这是我将表格视图单元格的文本字段绑定到自定义输入键盘的代码
CustomNumberPadViewController *calcKeyboard = [[CustomNumberPadViewController alloc] initWithNibName:@"CustomNumberPadView" bundle:nil];
calcKeyboard.equationViewController = self;
cell.variableValue.inputView = calcKeyboard.view;
我有绑定到 calkKeyboard 按钮的操作方法,当我按下按钮时,这些方法不会被调用。我什至已经实例化了一个“viewWillAppear”方法,当键盘出现时它也不会被调用。
我检查了数字键盘的类,它连接到包含上述方法的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
【问题讨论】:
标签: objective-c ios automatic-ref-counting