Label Result in another Viewcontroller - objective-c

Good Morning Guys,
I have a problem. I have an application that do a calculate. If i insert the Label in a same ViewController i watch all.
How do I insert the same Label in another View?
This is the view where there is the calculate.
H.
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *textField1;
#property (strong, nonatomic) IBOutlet UITextField *textField2;
#property (strong, nonatomic) IBOutlet UIButton *result;
#property (strong, nonatomic) IBOutlet UIDatePicker *data;
#end
M.
//
// ViewController.m
// IEcigarette
//
// Created by Federico on 24/11/12.
// Copyright (c) 2012 Federico. All rights reserved.
//
#import "ViewController.h"
#import "ResultViewController.h"
#interface ViewController ()
#property (strong, nonatomic) NSString * myString;
#property (strong, nonatomic) UILabel * myLabel;
#end
#implementation ViewController
-(IBAction)calculate:(id)sender{
NSDate *past = _data.date ;
NSDate *now = [NSDate date];
NSCalendar *gregorianCalendar = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSDayCalendarUnit;
NSDateComponents *components = [gregorianCalendar components:unitFlags
fromDate:past
toDate:now
options:0];
int z = [components day];
int a = ([_textField1.text intValue]);
int b = a*([_textField2.text intValue]);
int r = b * z / 20;
_myLabel.text = [[NSString alloc] initWithFormat:#"%d", r];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (BOOL)textFieldShouldReturn:(UILabel *)myLabel {
[myLabel resignFirstResponder];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self performSegueWithIdentifier:#"detail" sender:self];
}
return YES;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"detail"]) {
ResultViewController* destVC = (ResultViewController*)segue.destinationViewController;
destVC.myString = self.myLabel.text;
destVC.navigationItem.title = self.myLabel.text;
}
}
#end
Thank you

why you are trying to insert the same label to the another view also. just pass the label.text (string) to another view controller's string. then use that string and create a new label with this string in the viewdidload method . you can also pass the value using nsuserdefaults.

You could keep a reference to it in a shared and call:
[yourLabel removeFromSuperview];
[yourViewController.view addSubview:yourLabel];
for every view controller you want to display it on.
However if what you're sharing is pretty much functioning as a UILabel, I would recommend using separate UILabel instances for each view controller and just sharing the .text value across views. You could pass the value in prepareForSegue, save it to NSUserDefaults, set it as a property of some shared object/singleton.

Related

IBAction Method not being called when button is pushed. But View controller is being pushed

I am attempting to pass information from one viewController to another using a push segue with an IBAction button named *line. However from what I can tell this method is not being called and the NSLog(#"%#", see); I inserted to test the method is not displaying any message. Here is some code for the first viewController.
DetailController.m
#import "DetailController.h"
#import "City.h"
#import "ViewController.h"
#import "VideoController.h"
#import "Helper.h"
#interface DetailController ()
#property (nonatomic, strong) IBOutlet VideoController *videoViewController;
#end
#implementation DetailController
#synthesize city, ClubName, Price, Vip, Promo, remain,p,deal,money,camera,tweet,post;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.videoViewController = [[VideoController alloc] init];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320,1400)];
[super viewDidLoad];
UIImage *highlightedButtonImage = [UIImage imageNamed:#"twitter.png"];
UIImage *highlightedButtonImage2 = [UIImage imageNamed:#"twitter2.png"];
[Helper customizeBarButton:self.tweet image:highlightedButtonImage highlightedImage:highlightedButtonImage2];
UIImage *faceButtonImage = [UIImage imageNamed:#"facebook.png"];
UIImage *faceButtonImage2 = [UIImage imageNamed:#"facebook2.png"];
[Helper customizeBarButton:self.post image:faceButtonImage highlightedImage:faceButtonImage2];
UIImage *taxiButtonImage = [UIImage imageNamed:#"taxi.png"];
UIImage *taxiButtonImage2 = [UIImage imageNamed:#"taxi2.png"];
[Helper customizeBarButton:self.taxi image:taxiButtonImage highlightedImage:taxiButtonImage2];
// Do any additional setup after loading the view.
UIFont *labelFont=[UIFont fontWithName:#"King Kikapu" size:15.0];
UIFont *myFont=[UIFont fontWithName:#"Deutsch Gothic" size:20.0];
UIFont *myFont2=[UIFont fontWithName:#"Deutsch Gothic" size:35.0];
UIFont *titleFont=[UIFont fontWithName:#"Pornstar" size:50.0];
NSString * name= self.city.clubName;
NSString * line= self.city.clubLine;
NSString * description= self.city.promo;
NSString * price= self.city.price;
NSString *ipCam= self.city.camera;
remain.font=labelFont;
remain.text=#"VIP Remaining :";
p.font=labelFont;
p.text=#"Price :";
money.font=myFont;
deal.font=labelFont;
deal.text=#"Promotions :";
ClubName.font=titleFont;
ClubName.text=name;
Vip.font=myFont2;
Vip.text=line;
Price.font=myFont2;
Price.text=price;
Promo.font=myFont;
Promo.text=description;
}
- (IBAction)PostFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController * facebook= [[SLComposeViewController alloc]init];
facebook= [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:[NSString stringWithFormat:#"I'm heading to"]];
[self presentViewController:facebook animated:YES completion:nil];
[facebook setCompletionHandler:^(SLComposeViewControllerResult result){
NSString * output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output=#"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output=#"Post Succesful";
default:
break;
}
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
}];
}}
- (IBAction)PostTwitter:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet= [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"I'm heading to"];
[self presentViewController: tweetSheet animated:YES completion:nil];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)line:(id)sender {
NSString *see=self.city.camera;
NSLog(#"%#", see);
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle:nil];
self.videoViewController = [storyboard instantiateViewControllerWithIdentifier:#"Page3"];
self.videoViewController.city.camera= self.city.camera;
[self.navigationController pushViewController:self.videoViewController animated:YES];
}
#end
As a test I inserted NSLog(#"%#", see); into the IBAction method but this is not returning any value
DetailController.h
#import <UIKit/UIKit.h>
#import "VideoController.h"
#import <Social/Social.h>
#class City;
#interface DetailController : UIViewController {
IBOutlet UIScrollView *scroller;
}
#property (weak, nonatomic) IBOutlet UIBarButtonItem *taxi;
#property (strong,nonatomic) City *city;
#property (weak, nonatomic) IBOutlet UILabel *ClubName;
#property (weak, nonatomic) IBOutlet UILabel *Vip;
#property (weak, nonatomic) IBOutlet UILabel *Price;
#property (nonatomic, strong)NSString * camera;
#property (weak, nonatomic) IBOutlet UILabel *Promo;
#property (weak, nonatomic) IBOutlet UILabel *remain;
#property (weak, nonatomic) IBOutlet UILabel *p;
#property (weak, nonatomic) IBOutlet UILabel *deal;
#property (weak, nonatomic) IBOutlet UILabel *money;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *tweet;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *post;
- (IBAction)line:(id)sender;
#end
Thanks for any suggestions on why this method is not being called when the button is pushed
The only way for your IBAction to NOT get called is when the button is not appropriately connected to it. Double check that in the connections inspector.

Cant't show a integer in a label

I'm trying to make a very simple iOS app where an integer is created within a MutableArray.
The integer must present itself in an label in a Custom ViewController. Here is my code:
#interface Photo : NSObject
#property (nonatomic) NSString *name;
#property (nonatomic) NSString *filename;
#property (nonatomic) NSString *naam;
#property (nonatomic) int leeftijd;
#property (nonatomic) NSString *herkomst;
#property (nonatomic) NSString *club;
#end
My Custom TableViewController with an mutableArray.
#interface PhotosTableViewController () {
NSMutableArray *photos;
}
#end
#implementation PhotosTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Soccer Players";
// Create an array
photos = [[NSMutableArray alloc]init];
Photo *pic = [[Photo alloc]init];
pic.name = #"Ronaldo";
pic.filename = #"ronaldo";
pic.naam = #"Christano Ronaldo";
pic.leeftijd = 29;
pic.herkomst = #"Portugal";
pic.club = #"Real Madrid";
[photos addObject:pic];
And at last my Custom ViewController
#interface DisplayViewController ()
#property (weak, nonatomic) IBOutlet UIImageView *currentImage;
#property (weak, nonatomic) IBOutlet UILabel *nameLabel;
#property (weak, nonatomic) IBOutlet UILabel *ageLabel;
#property (weak, nonatomic) IBOutlet UILabel *countryLabel;
#property (weak, nonatomic) IBOutlet UILabel *clubLabel;
#end
#implementation DisplayViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:self.currentPhoto.filename];
[self.currentImage setImage:image];
self.nameLabel.text = [self.currentPhoto naam];
self.ageLabel.text = [self.currentPhoto leeftijd];
self.countryLabel.text = [self.currentPhoto herkomst];
self.clubLabel.text = [self.currentPhoto club];
}
Not sure what i'm doing wrong. I gave the integer a Property , gave it a amount en declared it in a label. Must be something very stupid, but can't see the solution on the web.
Thanks for your help!
You should 'convert' int to string:
self.ageLabel.text = [NSString stringWithFormat:#"%d", [self.currentPhoto leeftijd]];
Integer is not auto converted to NSString. Change
self.ageLabel.text = [self.currentPhoto leeftijd];
to
self.ageLabel.text = [[self.currentPhoto leeftijd] description];
or to
self.ageLabel.text = [NSString stringWithFormat:#"%i", [self.currentPhoto leeftijd]];
Lable only show NSString so you convert your int to NSString..
self.ageLabel.text = [NSString stringWithFormat:#"%d", [self.currentPhoto leeftijd]];

How to save UIImages in view

In my app I have two views: a mapView, and a detail view. The mapView has annotations, and the annotation views have right callout buttons that push the detail view onto the stack when the callout button is pressed. In the detail view, the user can take a picture that appears on the UIImage that is on the detail view controller. What I want is for a different image to be on the detail view controller for each annotation. I have read that I can use a singleton, and I have made a singleton class, but I do not know how to use it. Can someone help me out?
Here is some code:
My MKAnnotation class:
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface MapPoint : NSObject <MKAnnotation>
{
NSString *_address;
CLLocationCoordinate2D _coordinate;
NSNumber *_identifier;
UIImage *_image;
}
- (id)initWithAddress:(NSString*)address
coordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)t
identifier:(NSNumber *)ident;
//This is a required property from MKAnnotation
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
//This is an optional property from MKAnnotataion
#property (nonatomic, copy) NSString *title;
#property (nonatomic, readonly, copy) NSString *subtitle;
#property (nonatomic) BOOL animatesDrop;
#property (nonatomic) BOOL canShowCallout;
#property (copy) NSString *address;
#property (copy) NSNumber *identifier;
#property (copy,nonatomic) UIImage *image;
#end
#implementation MapPoint
#synthesize title, subtitle, animatesDrop, canShowCallout;
#synthesize address = _address, coordinate = _coordinate, identifier = _identifier, image = _image;
-(id)initWithAddress:(NSString *)address
coordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)t
identifier:(NSNumber *)ident
{
self = [super init];
if (self) {
_address = [address copy];
_coordinate = coordinate;
_identifier = ident;
[self setTitle:t];
NSDate *theDate = [NSDate date];
subtitle = [NSDateFormatter localizedStringFromDate:theDate
dateStyle:NSDateFormatterMediumStyle
timeStyle:NSDateFormatterMediumStyle];
}
return self;
}
#end
Here is the detail view controller:
#import <UIKit/UIKit.h>
#class P2OViewController;
#interface PinViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate,UITextFieldDelegate>
{
__weak IBOutlet UILabel *label;
__weak IBOutlet UIButton *removeButton;
NSString *addressForLabel;
__weak P2OViewController *_vc;
__weak NSNumber *_identifier;
}
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (weak, nonatomic) IBOutlet UIButton *removeButton;
#property (weak, nonatomic) P2OViewController *vc;
#property (weak, nonatomic) NSNumber *identifier;
-(void)takePicture:(id)sender;
-(void)buttonPressed:(id)sender;
#end
#import "PinViewController.h"
#import "MapPoint.h"
#import "P2OViewController.h"
#implementation PinViewController
#synthesize imageView, label, removeButton;
#synthesize vc = _vc, identifier = _identifier;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UIBarButtonItem *pic = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:#selector(takePicture:)];
[[self navigationItem]setRightBarButtonItem:pic];
}
return self;
}
-(void)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
//If our device has a camera, we ant to take a picture, otherwise, we just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagePicker setDelegate:self];
//Place the image picker on the screen
[self presentViewController:imagePicker
animated:YES
completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//Put the image onto the screen in out image view
[imageView setImage:image];
//Take image picker off the screen - you must call this dismiss method
[self dismissViewControllerAnimated:YES
completion:nil];
}
#end
You surely have a class implementing the MKAnnotation protocol.
In this class simply add a UIImage property and assign to every annotation its custom image.
Then when presenting the detailed view you just pass around the annotation and access its image property you defined.
EDIT
In your PinViewController simply declare a property like this
#property(nonatomic, strong) MapPoint * annotation;
Before you present your PinViewController assign the corresponding annotation to it, doing something like
detailedController.annotation = theAnnotation;
Do whatever you need to do to get the image, then store it in the annotation in this way
self.annotation.image = theImage;
Now the annotation is storing the image, so as long as you keep it in memory it will be there available for you.
The next time you push the detailed view you can perform a check to see whether that annotation has already an image or not
if(nil != self.annotation.image) {
// do something
} else {
// do something else
}

objective-c Tabbed App, Thread 1 signal: SIGABRT [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
I am writing an app from the Tabbed Application template in xCode.
Without any code, the app will switch tabs with no problems.
After adding code to the first view controller, I get an error when trying to switch tabs.
here is the error message:
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
The usual reason for this error is that somewhere in a xib file or storyboard you have a link from some control or view to an IBOutlet called 'solve' but you no longer have that property or variable defined in the code of the class where the link points.
I think you could get the detailed info in Xcode debugger or gdb, the call stack is very important info.
I did it and found the result that a identifier of tableviewcell is wrong.
UIViewController compliant to NSKeyValueCoding protocol, so when set a value for undeined key and you do not override
- (void)setValue:(id)value forUndefinedKey:(NSString *)key;
it will arise a NSUndefinedKeyException exception..
[self setTriText1:nil];
[self setTriText2:nil];
[self setLegA:nil];
[self setLegB:nil];
[self setHypotenuse:nil];
[self setAngleA:nil];
[self setAngleB:nil];
[self setButton1:nil];
may be here can brings that exception. why not you write it like this:
self.triText1 = nil;
self.triText2 = nil;
self.legA = nil;
as well for sencondViewContrlloer, if you use "set method" explicitly and write wrong method, similar exception will be happened..

cannot follow that tutorial

i tried to follow this tutorial:
http://www.youtube.com/watch?v=L-FK1TrpUng&feature=related
around 00:39:00.
Theres a counter which recognizes every switch to the second view controller and counts it.
The number of view switches should be shown on the second view controller.
But it doesn't work, thats the code:
Test2ViewController.h
#interface Test2ViewController : UIViewController <UITextFieldDelegate> {
UINavigationController *navController;
Test21ViewController *test21View;
NSString *text;
IBOutlet UITextField *textField1;
}
#property(nonatomic, retain) UITextField *textField1;
#property (nonatomic, retain) UINavigationController *navController;
#property (copy) NSString *text;
-(IBAction)pushViewController:(id)sender;
#end
Test2ViewController.m:
#import "Test2ViewController.h"
#import "Test21ViewController.h"
#implementation Test2ViewController
#synthesize textField1, navController, text;
-(IBAction)pushViewController:(id)sender {
static int count = 1;
Test21ViewController *test21ViewController = [[Test21ViewController alloc] init];
[self.navigationController pushViewController:test21ViewController animated:YES];
test21ViewController.label = [NSString stringWithFormat:#"Pushed %d", count];
count++;
}
Test21ViewController.h:
#interface Test21ViewController : UIViewController {
UINavigationController *navController;
NSString *label;
IBOutlet UILabel *textLabel;
UITextField *tF1;
}
#property (copy) NSString *label;
#property (nonatomic, retain) UINavigationController *navController;
#property(nonatomic,retain)UITextField *tF1;
-(IBAction)feldeingabe:(id)Sender;
#end
Test21ViewController.m:
#implementation Test21ViewController
#synthesize label;
- (void)viewDidLoad {
textLabel.text = label;
}
Any ideas why it doesn't work?
Thanks in advance
Code for the second question:
static int count = 1;
Test2ViewController *test2ViewController;
test2ViewController.label = [NSString stringWithFormat:#"Pushed %d !!!!!", count];
[[self navigationController] popViewControllerAnimated:NO];
count++;
CURRENT CODE:
#import "Test21ViewController.h"
#implementation Test21ViewController
#synthesize navController, text, parentView;
-(IBAction)pushViewController2:(id)sender {
Test2ViewController *test2ViewController;
static int count = 1;
test2ViewController.parentView = self;
test2ViewController.label = [NSString stringWithFormat:#"Pushed %d !!!!!", count];
[self.navigationController pushViewController:test2ViewController animated:YES]; count++;
}
For the second problem (passing a string from child to parent);
Test2ViewController.h
#interface Test2ViewController : UIViewController <UITextFieldDelegate> {
NSString *receiverPropertyFromChild;
}
#property(nonatomic, retain) NSString *receiverPropertyFromChild;
Test2ViewController.m:
-(IBAction)pushViewController:(id)sender {
static int count = 1;
Test21ViewController *test21ViewController = [[Test21ViewController alloc] init];
test21ViewController.label = [NSString stringWithFormat:#"Pushed %d", count];
test21ViewController.parentView = self;
[self.navigationController pushViewController:test21ViewController animated:YES];
count++;
}
Test21ViewController.h:
#class Test2ViewController;
#interface Test21ViewController : UIViewController {
Test2ViewController *parentView;
}
#property (nonatomic, assign) Test2ViewController *parentView;
Test21ViewController.m
-(IBAction)goToTest2ViewController:(id)sender {
parentView.receiverPropertyFromChild = #"the text you want to pass";
[self.navigationController popViewControllerAnimated:YES];
count++;
}
can you try:
Test21ViewController *test21ViewController = [[Test21ViewController alloc] init];
test21ViewController.label = [NSString stringWithFormat:#"Pushed %d", count];
[self.navigationController pushViewController:test21ViewController animated:YES];
I swapped the last two lines. It could be that you are setting the label after viewDidLoad has already been called, thus not setting the value in the label.
That said, it is better to pass the string as an init parameter, not as a property and then set in viewDidLoad.
edit:
To set it as init parameter, you need to create a new init method to accept that parameter.
- (id) initWithString:(NSString *)labelParam {
self = [super init];
if (self) {
this.label = labelParam;
}
return self;
}