OGeek|极客世界-中国程序员成长平台

标题: objective-c - EXC_BAD_ACCESS 切换到 ARC 时出错 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 21:47
标题: objective-c - EXC_BAD_ACCESS 切换到 ARC 时出错

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

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

CustomNumberPadViewController *calcKeyboard = [[CustomNumberPadViewController alloc] initWithNibName"CustomNumberPadView" bundle:nil];
calcKeyboard.equationViewController = self;
cell.variableValue.inputView = calcKeyboard.view;

我有绑定(bind)到 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)buttonPressedid)sender;
-(IBAction)buttonDonePressedid)sender;
-(IBAction)buttonDelPressedid)sender;


@end

以及相关的实现(为简洁起见,我已经删除了操作方法的内容,只留下了我的调试日志):

#import "CustomNumberPadViewController.h"
#import "VariableCellController.h"

@implementation CustomNumberPadViewController

@synthesize equationViewController;

- (id)initWithNibNameNSString *)nibNameOrNil bundleNSBundle *)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) viewWillAppearBOOL)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)buttonPressedid)sender{
    NSLog(@"61-CNPVC");    
}
-(IBAction)buttonDonePressedid)sender{
    NSLog(@"117-CNPVC");
}
-(IBAction)buttonDelPressedid)sender{
    NSLog(@"125-CNPVC");
}
@end



Best Answer-推荐答案


我认为您需要保留 CustomNumberPadViewController,方法是使用 addChildViewController 添加它或将其分配给属性。

尝试使用 zombies enabled 进行调试.

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4