objective-c - EXC_BAD_ACCESS 切换到 ARC 时出错
<p><p>我在表格 View 单元格中有一个文本字段,我想分配一个自定义输入键盘。我可以让键盘显示出来,但似乎没有连接相应的 Controller 类。当我按下任何按钮时,我会收到 EXC_BAD_ACCESS 错误或“无法识别的选择器”错误。</p>
<p>这是我将表格 View 单元格的文本字段绑定(bind)到自定义输入键盘的代码</p>
<pre><code>CustomNumberPadViewController *calcKeyboard = [ initWithNibName:@"CustomNumberPadView" bundle:nil];
calcKeyboard.equationViewController = self;
cell.variableValue.inputView = calcKeyboard.view;
</code></pre>
<p>我有绑定(bind)到 calkKeyboard 按钮的操作方法,当我按下按钮时,这些方法不会被调用。我什至已经实例化了一个“viewWillAppear”方法,当键盘出现时它也不会被调用。</p>
<p>我检查了数字键盘的类,它连接到包含上述方法的CustomNumberPadViewController。</p>
<p>这是我的 CustomNumberPadViewController 的代码:</p>
<pre><code>#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
</code></pre>
<p>以及相关的实现(为简洁起见,我已经删除了操作方法的内容,只留下了我的调试日志):</p>
<pre><code>#import "CustomNumberPadViewController.h"
#import "VariableCellController.h"
@implementation CustomNumberPadViewController
@synthesize equationViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = ;
if (self) {
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
;
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
-(void) viewWillAppear:(BOOL)animated
{
UIColor *backgroundPatern = [ initWithPatternImage:];
self.view.backgroundColor = backgroundPatern;
}
- (void)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
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您需要保留 CustomNumberPadViewController,方法是使用 <code>addChildViewController</code> 添加它或将其分配给属性。</p>
<p>尝试使用 <a href="https://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode" rel="noreferrer noopener nofollow">zombies enabled</a> 进行调试.</p></p>
<p style="font-size: 20px;">关于objective-c - EXC_BAD_ACCESS 切换到 ARC 时出错,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/9623473/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/9623473/
</a>
</p>
页:
[1]