xCodeのタブ付きアプリケーションテンプレートからアプリを作成しています。 コードなしで、アプリは問題なくタブを切り替えます。objective-cタブ付きアプリケーション、スレッド1シグナル:SIGABRT
最初のビューコントローラにコードを追加した後、タブを切り替えるときにエラーが発生します。
ここはエラーメッセージです:
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: の#import
@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
secondViewController.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
secondViewController.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
どのコードがfirstViewControllerで書かれていますか? Plsはそれを投稿します。 –
Xcodeに関する質問ではありません – Almo