7

我对 iOS 开发完全陌生,并且使用一本书来学习。按照前几章中的说明,我编写了一个简短的应用程序(代码如下)。它只需要一些文本输入并更改标签的文本以匹配它。但是,在模拟器中运行代码时,单击文本字段时出现以下错误:

2012-06-08 11:26:06.595 HelloNoun [14926:f803] 打开'/Users/clhu/Library/Application Support/iPhone Simulator/5.1/Library/Caches/com.apple.keyboards/images/1859589221'失败:'没有这样的文件或目录' (2)

2012-06-08 11:26:06.702 HelloNoun [14926:f803] 'INSERT INTO store VALUES (?,?,?,?,?,?,?,?)' 约束失败 (19)

然后,当我按下按钮设置标签时,我也会收到以下错误:

2012-06-08 11:27:09.050 HelloNoun [14926:f803]-[UIView 文本]:无法识别的选择器发送到实例 0xb75ac80

2012-06-08 11:27:09.051 HelloNoun [14926:f803] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIView 文本]:无法识别的选择器发送到实例 0xb75ac80”

*首先抛出调用栈:

(0x13c7022 0x1558cd6 0x13c8cbd 0x132ded0 0x132dcb2 0x21a7 0x13c8e99 0x1414e 0x140e6 0xbaade 0xbafa7 0xba266 0x393c0 0x395e6 0x1fdc4 0x13634 0x12b1ef5 0x139b195 0x12ffff2 0x12fe8da 0x12fdd84 0x12fdc9b 0x12b07d8 0x12b088a 0x11626 0x1dad 0x1d15) terminate called throwing an exception(lldb)

我已经检查了我的联系并多次回顾了我的步骤,并没有看到任何明显的错误(尽管我对此绝对很陌生)。谁能帮我指出正确的方向?谢谢!


这是代码:

// ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *userOutput;
@property (strong, nonatomic) IBOutlet UITextField *userInput;

- (IBAction)setOutput:(id)sender;

@end

// ViewController.m

#import "ViewController.h"

@implementation ViewController
@synthesize userOutput;
@synthesize userInput;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setUserOutput:nil];
    [self setUserInput:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)setOutput:(id)sender 
{
    self.userOutput.text = self.userInput.text;
}
@end
4

1 回答 1

4

我以前从未见过第一个错误,但您可以尝试删除路径处的缓存文件夹/Users/clhu/Library/Application Support/iPhone Simulator/5.1/Library/Caches。模拟器应该足够聪明以重新创建它。

对于第二个错误,我通常会看到当我将属性连接到 NIB 中的错误视图时。看起来该属性userOutput指向的是 UIView 而不是 UITextField。您可以检查您的 NIB 中的连接或通过将以下行添加到 setOutput:.

NSLog(@"%@", self.userOutput);

您日志中的输出应该类似于

<UITextField: 0x6fea9f0; frame = (0 0; 100 31); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6fec700>>

于 2012-06-08T16:01:25.537 回答