objective-c - EXC_BAD_ACCESS 切换到 ARC 时出错

标签 objective-c ios automatic-ref-counting

我的表格 View 单元格中有一个文本字段,我想分配一个自定义输入键盘。我可以让键盘显示出来,但似乎相应的 Controller 类没有连接。当我按下任何按钮时,我收到 EXC_BAD_ACCESS 错误,或“无法识别的选择器”错误。

这是我将表格 View 单元格的文本字段绑定(bind)到自定义输入键盘的代码

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

最佳答案

我认为您需要通过使用 addChildViewController 添加它或将其分配给属性来保留 CustomNumberPadViewController。

尝试使用 zombies enabled 进行调试.

关于objective-c - EXC_BAD_ACCESS 切换到 ARC 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9623473/

相关文章:

ios - 如何返回当前 View Controller ?

objective-c - Apple Keychain 丢失用户名/密码信息

iOS WKWebView - 无法添加 socket ,只能操作

ios - MKMapView 不会滚动 180 度

iphone - 使用 ARC 重新初始化/重新分配对象

iphone - 我需要在 ARC 中使用 dealloc 方法吗?

ios - 过程中的 UIProgressView 栏

iphone - UIView 阴影不显示

来自谷歌解析json的iOS地理编码数据

iphone - 为什么在 -dealloc 中注销通知接收器会在 ARC 下创建无限循环?