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

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..

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]];

Cannot compile with error, not sure what to do

I am Getting error message as follows...
"2014-01-28 21:17:56.878 Higher or Lower 2[5869:70b] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key enterButoonOut.'
* First throw call stack:"
//
// ViewController.m
// Higher or Lower 2
//
// Created by Michael Goedken on 1/27/14.
// Copyright (c) 2014 Michael Goedken. All rights reserved.
//
/
// Created by Michael Goedken on 1/27/14.
// Copyright (c) 2014 Michael Goedken. All rights reserved.
//
#import "ViewController.h"
int answer = 0;
int guess = 0;
int turn = 0;
BOOL timeStarted = NO;
#interface ViewController ()
#end
#implementation ViewController
- (IBAction)enterButton:(id)sender {
NSString *input = _labelGuess.text;
guess = [input intValue];
_previousLabel.text = [NSString stringWithFormat:#"%d",guess];
_labelGuess.text=#"";
turn++;
_guessesLabel.text = [NSString stringWithFormat:#"%d",turn];
if (timeStarted == NO){
seconds = 0;
timer = [NSTimer scheduledTimerWithTimeInterval:.001 target:self
selector:#selector(countUp) userInfo:nil repeats:YES];
}
timeStarted = YES;
if (guess < 1 || guess > 100){
_correct.hidden = YES;
_lower.hidden = YES;
_higher.hidden = YES;
_chooseNumber.hidden = YES;
_outOfRange.hidden = NO;
}
else if (guess > answer) {
_lower.hidden = NO;
_higher.hidden = YES;
_chooseNumber.hidden = YES;
_correct.hidden = YES;
_outOfRange.hidden = YES;
}
else if (guess < answer) {
_lower.hidden = YES;
_higher.hidden = NO;
_chooseNumber.hidden = YES;
_correct.hidden = YES;
_outOfRange.hidden = YES;
}
else {
_correct.hidden = NO;
_lower.hidden = YES;
_higher.hidden = YES;
_chooseNumber.hidden = YES;
_outOfRange.hidden = YES;
[timer invalidate];
_nextButtonOut.hidden = NO;
_enterButtonOut.hidden = YES;
_labelGuess.hidden = YES;
}
}
-(void) countUp {
milliSeconds ++;
seconds = milliSeconds / 1000;
minutes = seconds / 60;
remainingSeconds = seconds % 60;
remainingMilliSeconds = milliSeconds % 1000;
if (minutes > 0) {
_timerLabel.text = [NSString stringWithFormat:#"%2d:%.2d", minutes, remainingSeconds];
}
else {
_timerLabel.text = [NSString stringWithFormat:#"%2d:%.2d.%.3d", minutes,
remainingSeconds, remainingMilliSeconds];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[_labelGuess resignFirstResponder];
}
- (void)viewDidLoad
{
[super viewDidLoad];
_labelGuess.keyboardType = UIKeyboardTypeNumberPad;
_higher.hidden = YES;
_lower.hidden = YES;
_correct.hidden = YES;
_outOfRange.hidden = YES;
answer = arc4random() % 100 + 1;
_nextButtonOut.hidden = YES;
NSLog(#"Answer %i", answer);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)nextButton:(id)sender {
_correct.hidden = YES;
_lower.hidden = YES;
_higher.hidden = YES;
_chooseNumber.hidden = YES;enter code here
_outOfRange.hidden = YES;
_labelGuess.hidden = YES;
_guessesLabel.hidden = YES;
_previousLabel.hidden = YES;
_timerLabel.hidden = YES;
_nextButtonOut.hidden = YES;
_enterButtonOut.hidden = YES;
_background.hidden = YES;
_guesses.hidden = YES;
_previous.hidden = YES;
}
#end
//
// ViewController.h
// Higher or Lower 2
//
// Created by Michael Goedken on 1/27/14.
// Copyright (c) 2014 Michael Goedken. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
NSTimer *timer;
int seconds;
int minutes;
int remainingSeconds;
int milliSeconds;
int remainingMilliSeconds;
}
#property (weak, nonatomic) IBOutlet UIImageView *chooseNumber;
#property (weak, nonatomic) IBOutlet UITextField *labelGuess;
#property (weak, nonatomic) IBOutlet UIImageView *higher;
#property (weak, nonatomic) IBOutlet UIImageView *lower;
#property (weak, nonatomic) IBOutlet UIImageView *correct;
#property (weak, nonatomic) IBOutlet UIImageView *outOfRange;
#property (weak, nonatomic) IBOutlet UILabel *previousLabel;
#property (weak, nonatomic) IBOutlet UILabel *timerLabel;
#property (weak, nonatomic) IBOutlet UIButton *nextButtonOut;
#property (weak, nonatomic) IBOutlet UIButton *enterButtonOut;
#property (weak, nonatomic) IBOutlet UIImageView *background;
#property (weak, nonatomic) IBOutlet UILabel *previous;
#property (weak, nonatomic) IBOutlet UILabel *guessesLabel;
#property (weak, nonatomic) IBOutlet UILabel *guesses;
- (IBAction)nextButton:(id)sender;
- (IBAction)enterButton:(id)sender;
#end
I normally get this error message when one of a few things happens.
1) I have misspelled the value for segue.identifier as I'm about to segue to another module (not sure this applies in your case, but that is where it always gets me).
2) If you make changes to a storyboard, then go delete the value in code, the connection does not get eliminated in your storyboard and you have to manually go in and delete the link from within storyboard. To check, just right click (or ctrl click) on each element in a storyboard and note the connections.
My guess is if you look at that button in the storyboard, you will see "enterButoonOut" instead of "enterButtonOut"
Hope this helps!
Glenn
You have misspelled enterButoonOut and it must be enterButtonOut as per your declaration:
#property (weak, nonatomic) IBOutlet UIButton *enterButtonOut;

Not receiving reply from notification

I am trying to get a reply from a notification and pass the string to a label.
But the label (nResponse) does not change after I give the reply, why isn't the label updating? Is there a problem with the "activationType" method?
AppDelegate.h
#property (weak) IBOutlet NSTextField *nTitle;
#property (weak) IBOutlet NSTextField *nMessage;
-(IBAction)showNotification:(id)sender;
#property (weak) IBOutlet NSTextField *nResponse;
#property (assign) IBOutlet NSWindow *window;
#property BOOL hasReplyButton NS_AVAILABLE(10_9, NA);
#property (copy) NSString *responsePlaceholder NS_AVAILABLE(10_9, NA);
#property (readonly) NSAttributedString *response NS_AVAILABLE(10_9, NA);
#property (copy) NSImage *contentImage NS_AVAILABLE(10_9, NA);
#end
AppDelegate.m
#synthesize nTitle;
#synthesize nMessage;
#synthesize nResponse;
#synthesize window;
- (IBAction)showNotification:(id)sender{
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = [nTitle stringValue];
notification.informativeText = [nMessage stringValue];
notification.soundName = NSUserNotificationDefaultSoundName;
notification.responsePlaceholder = #"Reply";
notification.hasReplyButton = true;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification;
{
if (notification.activationType == NSUserNotificationActivationTypeReplied){
NSString* userResponse = notification.response.string;
[nResponse setStringValue:userResponse]; //set label to response
NSLog(#"%#", userResponse);
}
return YES;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
}
#end
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
center.delegate = self;
You should also make sure your Notice class implements the NSUserNotificationCenterDelegate protocol.

Converting UITextField to UILabel through view Controllers

I'm sure there is a simple explanation for this.
I am looking to transfer the data (not store) but transfer the text the user types into a text field and display it as a UILabel in another ViewController.
I already know how to convert text entered by the user into a label on the same viewcontroller.
I guess my problem is importing.
the .h:
#interface ViewController : UIViewController {
IBOutlet UITextField *firstPerson;
IBOutlet UITextField *secondPerson;
IBOutlet UIButton *calculateButton;
NSString *firstName;
NSString *secondName;
}
#property (nonatomic, retain) IBOutlet UITextField *firstPerson;
#property (nonatomic, retain) IBOutlet UITextField *secondPerson;
#property (nonatomic, retain) NSString *firstName;
#property (nonatomic, retain) NSString *secondName;
#property (nonatomic, retain) IBOutlet UIButton *calculateButton;
-(IBAction)calculate;
#end
the .m:
-(IBAction)calculate {
//Linked to UIButton
//This is the first View Controller.
// firstName = firstPerson.text;
// secondName = secondPerson.text;
secondViewController = [[ShowStats alloc] init];
}
my secondview controller .m (ShowStats):
#import "ShowStats.h"
#import "ViewController.h"
- (void)viewDidLoad
{
firstName = firstPerson.text;
secondName = secondPerson.text;
[super viewDidLoad];
}
Many thanks!
EDIT
ViewController.h
#import <UIKit/UIKit.h>
#import "ShowStats.h"
#interface ViewController : UIViewController {
IBOutlet UITextField *firstPerson;
IBOutlet UITextField *secondPerson;
IBOutlet UIButton *calculateButton;
//NSString *firstName;
// NSString *secondName;
}
#property (nonatomic, retain) IBOutlet UITextField *firstPerson;
#property (nonatomic, retain) IBOutlet UITextField *secondPerson;
//#property (nonatomic, retain) NSString *firstName;
//#property (nonatomic, retain) NSString *secondName;
#property (nonatomic, retain) IBOutlet UIButton *calculateButton;
-(IBAction)calculate;
#end
ViewController.m
#import "ViewController.h"
#import "ShowStats.h"
#implementation ViewController
#synthesize firstPerson, secondPerson;
//#synthesize firstName, secondName;
#synthesize calculateButton;
ShowStats *secondViewController;
-(IBAction)calculate {
secondViewController = [[ShowStats alloc] init];
secondViewController.firstName = firstPerson.text;
}
ShowStats.h
#interface ShowStats : UIViewController{
IBOutlet UILabel *nameStats;
}
#property (nonatomic, retain) IBOutlet UILabel *nameStats;
#property (nonatomic, retain) NSString *firstName;
#property (nonatomic, retain) NSString *secondName;
#end
ShowStats.m
- (void)viewDidLoad
{
nameStats.text = [NSString stringWithFormat:#"%#", firstName];
//secondLabel.text = self.secondName;
[super viewDidLoad];
}
Make these properties in ShowStats class
#property (nonatomic, retain) NSString *firstName;
#property (nonatomic, retain) NSString *secondName;
and change this to this
-(IBAction)calculate {
secondViewController = [[ShowStats alloc] init];
secondViewController.firstName = firstPerson.text;
secondViewController.secondName = secondPerson.text;
}
then set these strings to UILablel in your viewDidLoad
In ShowStats.h, add the following:
#property(nonatomic, copy) NSString* firstName;
#property(nonatomic, copy) NSString* secondName;
In ShowStats.m add/update the following:
#synthesize firstName, secondName;
//...
- (id) init {
if (self = [super init]) {
self.firstName = nil;
self.secondName = nil;
//...
}
return self;
}
- (void) dealloc {
self.firstName = nil;
self.secondName = nil;
//...
[super dealloc];
}
- (void)viewDidLoad {
//or even better, do this in viewWillAppear instead
firstLabel.text = self.firstName;
secondLabel.text = self.secondName;
//...
[super viewDidLoad];
}
Finally, in ViewController.m, implement calculate like this:
-(IBAction)calculate {
//Linked to UIButton
//This is the first View Controller.
// firstName = firstPerson.text;
// secondName = secondPerson.text;
secondViewController = [[ShowStats alloc] init];
secondViewController.firstName = firstPerson.text;
secondViewController.secondName = secondPerson.text;
//display the view controller here
[secondViewController autorelease];
}
If it is a navigation then in your SecondViewController you can call:
ViewController *viewController = [self.navigationController.viewControllers objectAtIndex:0];
firstName = [[viewController firstPerson] text];
secondName = [[viewController secondPerson] text];
Or you could do the following for a Single View app:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
ViewController *viewController = [appDelegate viewController];
firstName = [[viewController firstPerson] text];
secondName = [[viewController secondPerson] text];
* EDIT *
Add two labels to your .h file (nonatomic, retain) & synthesize in .m . Initialize the labels in viewDidLoad then set them (assuming they are called label1 and label2):
[label1 setText:firstName];
[label2 setText:secondName];