Objective-c 选项卡式应用程序,线程 1 信号 : SIGABRT

标签 objective-c cocoa-touch uikit

我正在 xCode 中的选项卡式应用程序模板编写一个应用程序。 无需任何代码,应用程序将毫无问题地切换选项卡。

将代码添加到第一个 View Controller 后,尝试切换选项卡时出现错误。

这是错误消息:

2012-04-26 09:43:01.171 Triangle Solver[9516:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TriSecondViewController 0x68827d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key solve.'
*** First throw call stack: (0x13ce022 0x155fcd6 0x13cdee1 0x9c6022 0x937f6b 0x937edb 0x952d50 0x23a71a 0x13cfdea 0x13397f1 0x23926e 0xdf1fc 0xdf779 0xdf99b 0xfb0a9 0xfaedd 0xf94aa 0xf934f 0xfae14 0x13cfe99 0x1b14e 0x1b0e6 0x2434bd 0x13cfe99 0x1b14e 0x1b0e6 0xc1ade 0xc1fa7 0xc1b13 0x245c48 0x13cfe99 0x1b14e 0x1b0e6 0xc1ade 0xc1fa7 0xc1266 0x403c0 0x405e6 0x26dc4 0x1a634 0x12b8ef5     0x13a2195 0x1306ff2 0x13058da 0x1304d84 0x1304c9b 0x12b77d8 0x12b788a 0x18626 0x2a0d 0x2975) terminate called throwing an exception(lldb)

firstViewResponder.h: #导入

@interface TriFirstViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *triText1;
@property (weak, nonatomic) IBOutlet UITextField *triText2;
- (IBAction)calc:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *legA;
@property (weak, nonatomic) IBOutlet UILabel *legB;
@property (weak, nonatomic) IBOutlet UILabel *hypotenuse;
@property (weak, nonatomic) IBOutlet UILabel *angleA;
@property (weak, nonatomic) IBOutlet UILabel *angleB;

@property (weak, nonatomic) IBOutlet UIButton *button1;

@property (copy, nonatomic) NSString *text1;
@property (copy, nonatomic) NSString *text2;

@end

第二个ViewController.h:

@interface TriSecondViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *sines1;
@property (weak, nonatomic) IBOutlet UITextField *sines2;
@property (weak, nonatomic) IBOutlet UITextField *sines3;
- (IBAction)solve2:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *angleA;
@property (weak, nonatomic) IBOutlet UILabel *sideA;
@property (weak, nonatomic) IBOutlet UILabel *angleB;
@property (weak, nonatomic) IBOutlet UILabel *sideB;
@property (weak, nonatomic) IBOutlet UILabel *angleC;
@property (weak, nonatomic) IBOutlet UILabel *sideC;

@property (weak, nonatomic) IBOutlet UISegmentedControl *segControl;
- (IBAction)aassas:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *sine1;
@property (weak, nonatomic) IBOutlet UILabel *sine2;
@property (weak, nonatomic) IBOutlet UILabel *sine3;

@end

firstViewController.m: @interface TriFirstViewController()

@end

@implementation TriFirstViewController
@synthesize legA;
@synthesize legB;
@synthesize hypotenuse;
@synthesize angleA;
@synthesize angleB;
@synthesize button1;
@synthesize triText1;
@synthesize triText2;

@synthesize text1;
@synthesize text2;

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

- (void)viewDidUnload
{
    [self setTriText1:nil];
    [self setTriText2:nil];
    [self setLegA:nil];
    [self setLegB:nil];
    [self setHypotenuse:nil];
    [self setAngleA:nil];
    [self setAngleB:nil];
    [self setButton1:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (IBAction)calc:(id)sender 
{
    double aa = 0;
    double ab = 0;
    double la = 0;
    double lb = 0;
    double h = 0;

    self.text1 = self.triText1.text;
    self.text2 = self.triText2.text;

    aa = [self.text1 doubleValue];
    lb = [self.text2 doubleValue]; 

    ab = 90 - aa;

    la = (tan((aa * (M_PI/180))) * lb);
    h = (pow(la, 2) + pow(lb, 2));
    h = sqrt(h);

    self.legA.text = [NSString stringWithFormat: @"%.2lf", la];
    self.legB.text = [NSString stringWithFormat: @"%.2lf", lb];
    self.angleA.text = [NSString stringWithFormat: @"%.2lf", aa];
    self.angleB.text = [NSString stringWithFormat: @"%.2lf", ab];
    self.hypotenuse.text = [NSString stringWithFormat: @"%.2lf", h];
}

@end

第二个ViewController.m:

@interface TriSecondViewController ()

@end

@implementation TriSecondViewController
@synthesize sine1;
@synthesize sine2;
@synthesize sine3;
@synthesize angleA;
@synthesize sideA;
@synthesize angleB;
@synthesize sideB;
@synthesize angleC;
@synthesize sideC;
@synthesize segControl;
@synthesize sines1;
@synthesize sines2;
@synthesize sines3;

BOOL mode = NO;

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

- (void)viewDidUnload
{
    [self setSines1:nil];
    [self setSine2:nil];
    [self setSines3:nil];
    [self setAngleA:nil];
    [self setAngleB:nil];
    [self setAngleC:nil];
    [self setSideA:nil];
    [self setSideB:nil];
    [self setSideC:nil];
    [self setSine1:nil];
    [self setSine2:nil];
    [self setSine3:nil];
    [self setSegControl:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (IBAction)solve2:(id)sender 
{
    if (mode)
    {
        double aa = [self.sines1.text doubleValue]; 
        double ab = [self.sines2.text doubleValue];
        double ac = 180 - aa - ab;
        double sa = [self.sines3.text doubleValue];
        double sb;
        double sc;

        //convert degrees to radians
        aa = (aa * (M_PI/180));
        ab = (ab * (M_PI/180));
        ac = (ac * (M_PI/180));

        sb = (sa/sin(aa))*sin(ab);
        sc = (sa/sin(aa))*sin(ac);

        self.angleA.text = [NSString stringWithFormat: @"%.2lf", aa];
        self.angleB.text = [NSString stringWithFormat: @"%.2lf", ab];
        self.angleC.text = [NSString stringWithFormat: @"%.2lf", ac];
        self.sideA.text = [NSString stringWithFormat: @"%.2lf", sa];
        self.sideB.text = [NSString stringWithFormat: @"%.2lf", sb];
        self.sideC.text = [NSString stringWithFormat: @"%.2lf", sc];
    }

    if (!mode) 
    {
        double aa = [self.sines1.text doubleValue];
        double ab;
        double ac;
        double sa = [self.sines2.text doubleValue];
        double sb = [self.sines3.text doubleValue];
        double sc;

        aa = (aa * (M_PI/180));

        ab = asin(sb*(sin(aa)/sa));
        ac = 180 - aa - ab;

        ac = (ac * (M_PI/180));

        sc = (sa/sin(aa))*sin(ac);

        self.angleA.text = [NSString stringWithFormat: @"%.2lf", aa];
        self.angleB.text = [NSString stringWithFormat: @"%.2lf", ab];
        self.angleC.text = [NSString stringWithFormat: @"%.2lf", ac];
        self.sideA.text = [NSString stringWithFormat: @"%.2lf", sa];
        self.sideB.text = [NSString stringWithFormat: @"%.2lf", sb];
        self.sideC.text = [NSString stringWithFormat: @"%.2lf", sc];
    }
}

- (IBAction)aassas:(id)sender 
{
    switch (self.segControl.selectedSegmentIndex) {
        case 0:
            self.sine1.text = @"Angle A/n";
            self.sine2.text = @"Angle B/n";
            self.sine3.text = @"Side A/n";
            mode = NO;
            break;

        case 1:
            self.sine1.text = @"Angle A/n";
            self.sine2.text = @"Side A/n";
            self.sine3.text = @"Side B/n";
            mode = YES; 
            break;

        default:
            break;
    }
}
@end

最佳答案

此错误的常见原因是,在 xib 文件或 Storyboard 中的某个位置,您有从某个控件或 View 到名为“solve”的 IBOutlet 的链接,但您不再在类的代码中定义该属性或变量链接指向的位置。

关于Objective-c 选项卡式应用程序,线程 1 信号 : SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10335252/

相关文章:

cocoa - 如果所有方法都是可选的,那么协议(protocol)的目的是什么?

objective-c - PrepareForSegue 与 UIImagePickerController

ios - CFReadStreamRead 中的 EXC_BREAKPOINT 崩溃

ios 用户如何取消 facebook 登录?

iphone - UIPageControl 不响应触摸,不改变点

ios - 移动 UITextField 的左 View

ios - 保持键盘始终在顶部且可见

ios - UIActivityViewController 上缺少关闭按钮

objective-c - 带圆角和阴影的 NSWindow

ios - MVC 和导入 UIKit