SIGARBT error crashing app - iphone

I built this calculator app in xcode 4.5 the digits work as expected but the operations ie (+,- ,c)worked once and never since they only return Nan and inf and the enter button always crashes the app and returns the error below.I built the UI in the storyboard and linked buttons to relevant methods
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CalculatorAppDelegate
class]));
This is my CalculatorViewController.h
#import <UIKit/UIKit.h>
#interface CalculatorViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *display;
#end
This is my CalculatorViewController.m
#import "CalculatorViewController.h"
#import "CalculatorBrain.h"
#interface CalculatorViewController ()
#property(nonatomic) BOOL userIsInTheMidleOfEnteringANumber;
#property (nonatomic, strong)CalculatorBrain *brain;
#end
#implementation CalculatorViewController
#synthesize display = _display;
#synthesize userIsInTheMidleOfEnteringANumber =_userIsInTheMidleOfEnteringANumber;
#synthesize brain = _brain;
- (CalculatorBrain *)brain
{
if (!_brain)_brain=[[CalculatorBrain alloc]init];
return _brain;
}
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = sender.currentTitle;
if (self.userIsInTheMidleOfEnteringANumber){
self.display.text = [self.display.text stringByAppendingString:digit];
}
else {
self.display.text = digit;
self.userIsInTheMidleOfEnteringANumber=YES;
}
}
- (IBAction)enterPressed
{
NSLog(#"im hre");
[self.brain pushOperand:[self.display.text doubleValue]];
self.userIsInTheMidleOfEnteringANumber=NO;
}
- (IBAction)operationPresed:(UIButton *)sender
{
if (self.userIsInTheMidleOfEnteringANumber) [self enterPressed];
double result =[self.brain performOperation:sender.currentTitle];
NSString *resultString= [NSString stringWithFormat:#"%g",result];
self.display.text= resultString;
}
#end
This is my CalculatorBrain.h
#import <Foundation/Foundation.h>
#interface CalculatorBrain : NSObject
-(void)pushOperand:(double)operand;
-(double)performOperation:(NSString *)operation;
#end
This is my CalculatorBrain.m
#import "CalculatorBrain.h"
#interface CalculatorBrain()
#property (nonatomic,strong)NSMutableArray *operandStack;
#end
#implementation CalculatorBrain
#synthesize operandStack = _operandStack;
-(NSMutableArray *)operandStack
{
if (_operandStack== nil) _operandStack =[[NSMutableArray alloc] init];
return _operandStack;
}
-(void)pushOperand:(double)operand
{
[self.operandStack addObject:[NSNumber numberWithDouble:operand]];
}
-(double)popOperand
{
NSNumber *operandObject = [self.operandStack lastObject];
if (operandObject) [self.operandStack removeLastObject];
return [operandObject doubleValue];
}
-(double)performOperation:(NSString *)operation
{
double result=0;
//calculate result
if ([operation isEqualToString:#"+"])
{
result =[self popOperand]+ [self popOperand];
}
else if ([operation isEqualToString:#"*"])
{
result = [self popOperand] * [self popOperand];
}
else if ([operation isEqualToString:#"-"]) {
result = [self popOperand] - [self popOperand];
}
else if ([operation isEqualToString:#"/"]) {
result = [self popOperand] / [self popOperand];
}
[self pushOperand:result];
return result;
}
#end
Im working from an example and have followed all steps i dont understand what im doing wrong the enterPressed method does not have a type ie UIButton This is my console output
2013-05-17 15:05:15.221 Calculator[786:11303] im hre
2013-05-17 15:05:15.280 Calculator[786:11303] -[CalculatorViewController enterPressed:]: unrecognized selector sent to instance 0x922a620
2013-05-17 15:05:15.288 Calculator[786:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CalculatorViewController enterPressed:]: unrecognized selector sent to instance 0x922a620'
*** First throw call stack:
(0x1c8e012 0x10cbe7e 0x1d194bd 0x1c7dbbc 0x1c7d94e 0x10df705 0x16920 0x168b8 0xd7671 0xd7bcf 0xd6d38 0x4633f 0x46552 0x243aa 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x1be87e3 0x1be8668 0x1365c 0x1f0d 0x1e35)
libc++abi.dylib: terminate called throwing an exception
(lldb)
any help will b appreciated

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CalculatorViewController enterPressed:]: unrecognized selector sent to instance 0x922a620' is the answer here. Check if your have the method enterPressed:in your CalculatorViewController class. I'm sure it's somehow misspelled if not missing

Change method signature:
- (IBAction)enterPressed
to
- (IBAction)enterPressed:(id)sender

In your CalculatorViewController.m file replace
- (IBAction)enterPressed
to
- (IBAction)enterPressed:(UIButton *)sender

I had this exact same problem actually... I deleted the Enter button and recreated it and then it worked after. Good luck, I wanted to pull my hair out

There are many working answers out there below. The reason why you have ran into this issue is, the method which you have linked in your xib file against one of your button appear on xib, points to enterPressed: - A method with an argument (enterPressed followed by a colon), but you have coded a method without an argument (enterPressed), hence it leads to a crash. Code tried to find a method with an argument which you have linked in your xib file, but it didn't find it, leads to a crash saying - ' unrecognized selector sent to instance'
Hence just replace
- (IBAction)enterPressed
with this:
- (IBAction)enterPressed:(UIButton *)sender

Related

Move from one controller to another with segue and story boards

I have finished the first tutorial in the apple developer tool resources where you make an input, label and button what I want is to make it so when you press the button it takes you to a new scene so i have set up the segue, and i'd it as "testPush" now how do i actually get it to move when i push the button i get an error saying
**Thread 1: signal SIGABRT**
And the code that it is replying to is this
return UIApplicationMain(argc, argv, nil, NSStringFromClass([HelloWorldAppDelegate class]));
Anyone got any idea's i know u need to add in code for the segue to work however everything i have seen doesn't make sense or its jsut a block of code with little to none instruction on what it means how u get it to work etc. Thanks for any and all help
Other stuff you might need i'm not to sure
Scene one is called: HelloWorldViewController
Scene two is called: HelloWorldViewController2
EDIT
Heres the code from my scripts encase you need that thanks.
HelloWorldViewController.m
#import "HelloWorldViewController.h"
#interface HelloWorldViewController ()
#property (weak, nonatomic) IBOutlet UITextField *textField;
#property (weak, nonatomic) IBOutlet UILabel *label;
- (IBAction)changeGreeting:(id)sender;
#end
#implementation HelloWorldViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 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)changeGreeting:(id)sender {
self.userName = self.textField.text;
NSString *nameString = self.userName;
if ([nameString length] == 0) {
nameString = #"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:#"Hello, %#!", nameString];
self.label.text = greeting;
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.textField) {
[theTextField resignFirstResponder];
}
return YES;
}
#end
HelloWorldViewController.h
#import <UIKit/UIKit.h>
#interface HelloWorldViewController : UIViewController <UITextFieldDelegate>
#property (copy,nonatomic) NSString *userName;
#end
And main.m
#import <UIKit/UIKit.h>
#import "HelloWorldAppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([HelloWorldAppDelegate class]));
}
}
try adding a performseguewithidentifier in your IBAction, something like the following:
- (IBAction)changeGreeting:(id)sender {
self.userName = self.textField.text;
NSString *nameString = self.userName;
if ([nameString length] == 0) {
nameString = #"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:#"Hello, %#!", nameString];
self.label.text = greeting;
[self performSegueWithIdentifier:#"segueId" sender:nil];
}
that should push the new for you.

Delegate not getting set in iOS5 StoryBoard UISplitViewController

I have a Universal app with UISplitViewConroller. I am using storyboards.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
LeftViewContrller *lcontroller = (LeftViewContrller *)masterNavigationController.topViewController;
id<SplitViewDelegate> rightController = (id<SplitViewDelegate>)[splitViewController.viewControllers objectAtIndex:1];
lcontroller.delegate = rightController;
}
I have a left and right controller for UISplitViewController app.
LeftViewController has a custom delegate, which is set as RightViewController.
//Custom delegate
#protocol SplitViewDelegate <NSObject>
- (void) matchSelectionChanged:(NSString *)curSelection;
#end
//LeftViewContoller
#interface LeftViewContrller : UITableViewController {
id<SplitViewDelegate> _delegate;
NSMutableArray *_matches;
}
#property (strong) id<SplitViewDelegate> delegate;
#property (strong) NSMutableArray *matches;
#end
RightViewController implements this delegate protocol. However, when cell inside row is clicked in LeftViewController the delegates failing.
//RightViewController
#interface RightViewController : UIViewController <SplitViewDelegate>
#property (weak,nonatomic) IBOutlet UILabel *matchLabel;
#end
//Implementation of RightViewController
- (void) matchSelectionChanged:(NSString *)curSelection {
self.matchLabel.text = curSelection;
//[self refresh];
}
//Did select row in LeftViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableString *s = [[NSMutableString alloc] initWithString:#"Row selected"];
if (_delegate != nil) {
[s appendFormat:#" %d ", indexPath.row];
[_delegate matchSelectionChanged:s];
}
}
//Get error
CustomViewTab[1200:11303] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController matchSelectionChanged:]: unrecognized selector sent to instance 0xda6a770'
* First throw call stack:
(0x1559052 0x1da8d0a 0x155aced 0x14bff00 0x14bfce2 0x1204e 0x62071d 0x620952 0x25986d 0x152d966 0x152d407 0x14907c0 0x148fdb4 0x148fccb 0x2500879 0x250093e 0x590a9b 0x1df8 0x1d55)
terminate called throwing an exception
I see didSelectRowAtIndex called but then RightViewController's matchSelectionChanged:(NSString *)curSelection never gets called.
Bit of an old question but I stumbled up on it and at a glance do you have the correct delegate?
#interface RightViewController : UIViewController <UISplitViewControllerDelegate>
I'm looking at iOS7 so maybe its changed since iOS5

unrecognized selector sent to instance

I have an NSObject called FHSUploadManager, which is a singleton object. Everything has appears to be working, expect today I been getting some strange messages.
2011-09-16 13:26:05.892 FHMedia[6038:6903] -[FHSUploadManager initialize]: unrecognized selector sent to instance 0x6b96900
2011-09-16 13:26:06.975 FHMedia[6038:6903] *** NSInvocation: warning: object 0xb0352cb8 of class 'úè0°8s†Gà–!Ä' does not implement methodSignatureForSelector: -- trouble ahead
2011-09-16 13:26:06.983 FHMedia[6038:6903] *** NSInvocation: warning: object 0xb0352cb8 of class 'úè0°8s†Gà–!Ä' does not implement doesNotRecognizeSelector: -- abort
It does not look like anything is broken, but these messages have me concern. Has anyone seen this before? Anyone have an idea on how to debug this?
I have taken out some of the methods for privacy and space.
Here is my FHSUploadManager.h
#class ListObject;
#class MergedItem;
#class ServerSync;
#class AppDelegate_Shared;
#class RegisteredUser;
#interface FHSUploadManager : NSObject {
NSMutableArray *uploadItems;
NSMutableArray *objectIds;
// KVO values
BOOL isSyncing;
NSString *uploadingStatus;
ListObject *uploadObject;
AppDelegate_Shared *appDelegate;
ServerSync *sync;
}
#property (assign) BOOL isSyncing;
#property (assign) NSString *uploadingStatus;
#property (assign) ListObject *uploadObject;
#property (assign) AppDelegate_Shared *appDelegate;
#end
Here is FHSUploadManager.m
#import "FHSUploadManager.h"
#import "ListObject.h"
#import "Reachability.h"
#import "ServerSync.h"
#import "AppDelegate_Shared.h"
#import "ItemAttribute.h"
#import "CoreItem.h"
#import "Media.h"
#import "MergedItem.h"
#import "WebServices.h"
#import "NSManagedObject+XML.h"
#import "NSNotificationCenter+MainThread.h"
#import "PowerMeXMLParser.h"
#import "RegisteredUser.h"
#import "TBXML.h"
static FHSUploadManager* sharedInstanceFHSUploadManager = nil;
#implementation FHSUploadManager
#synthesize isSyncing;
#synthesize uploadingStatus;
#synthesize uploadObject;
#synthesize appDelegate;
- (void)dealloc {
[uploadItems release];
[uploadingStatus release];
[uploadObject release];
[objectIds release];
[sync release];
[super dealloc];
}
-(void)startUpload
{
if( !isSyncing )
{
self.isSyncing = YES;
[self performSelectorInBackground:#selector(uploadingInBackground) withObject:nil];
}
}
// !!! Other methods and not added here. !!!
#pragma mark - Apple Boiler Plate Singleton -
+ (FHSUploadManager*)sharedInstance {
#synchronized(self)
{
if (sharedInstanceFHSUploadManager == nil) {
sharedInstanceFHSUploadManager = [[super allocWithZone:NULL] init];
sharedInstanceFHSUploadManager.isSyncing = NO;
sharedInstanceFHSUploadManager.appDelegate = (AppDelegate_Shared*)[[UIApplication sharedApplication] delegate];
}
}
return sharedInstanceFHSUploadManager;
}
+ (id)allocWithZone:(NSZone *)zone {
return [[self sharedInstance] retain];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (id)retain {
return self;
}
- (NSUInteger)retainCount {
return NSUIntegerMax; //denotes an object that cannot be released
}
- (void)release {
//do nothing
}
- (id)autorelease {
return self;
}
#end
Update After comment saying it was gone
It is back! I talked with a fellow programmer and he is wondering if I am stomping on some memory. So I am going to look into a little bit more.
Looks like you are not inheriting from NSObject...
The FHSUploadManager object class is deallocating. In the Edit Schemes Enable Zombie Objects. You will get log of the deallocated instance.
You may be accessing the object once it is freed.
Add a breakpoint on FHSUploadManager dealloc method.

Iphone : unrecognized selector sent to instance & viewDidLoad isn't running

I'm developing an application.
I used a TabBar and every tab have its Class (FirstViewController, SecondViewController, ... )
There is one AppDelegate too.
When I launch the program, the first Class is running.
When i select the second tab, the Secondview.xib 's running but the "viewDidLoad" isn't working.
When I select the third Tab, that's the same.
I've put some buttons on the third tab, and when I push it, I have a
> -[UIViewController testAuthentication:]: unrecognized selector sent to instance 0x5f16920
2011-04-08 13:46:42.511 e-mars[19501:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController testAuthentication:]: unrecognized selector sent to instance 0x5f16920'
Here's the code of my classes
SecondViewController.h
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController {
}
#end
SecondViewController.m
#import "SecondViewController.h"
#implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"viewDidLoad de SecondViewController");
NSURL *url = [NSURL URLWithString: #"http://iosdevelopertips.com/images/logo-iphone-dev-tips.png"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
[self.view addSubview:[[UIImageView alloc] initWithImage:image]];
}
- (void)dealloc {
[super dealloc];
}
#end
ThirdViewController.h
#import <UIKit/UIKit.h>
#interface ThirdViewController : UIViewController {
IBOutlet UITextField *login;
IBOutlet UITextField *motdepasse;
NSMutableData *responseData;
}
#property (retain, nonatomic) UITextField *login;
#property (retain, nonatomic) UITextField *motdepasse;
#property (retain, nonatomic) NSMutableData *responseData;
- (IBAction) testAuthentication: (id)sender;
- (IBAction) saveAuthentication: (id)sender;
#end
ThirdViewController.m
#import "ThirdViewController.h"
#implementation ThirdViewController
#synthesize login;
#synthesize motdepasse;
#synthesize responseData;
- (id)initWithFrame:(CGRect)frame {
//if ((self = [super initWithFrame:frame])) {
// Initialization code
//}
return self;
}
-(IBAction) testAuthentication: (id)sender {
//NSLog(#"testAuthentication");
}
- (IBAction) saveAuthentication: (id)sender {
NSLog(#"saveAuthentication");
}
- (void)dealloc {
[login dealloc];
[motdepasse dealloc];
[responseData dealloc];
[super dealloc];
}
#end
Your third ViewController doesn't actually create an instance, so no instance methods can be called upon it. Fix your initWithFrame: method. Remember: instance methods start with the '-' sign, class methods start with the '+' sign.
- (id)initWithFrame:(CGRect)frame {
self = [super initWithNibName:nil bundle:nil];
if (self)) {
// Initialization code
}
return self;
}
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
return [self initWithFrame:CGRectZero];
}
- (id)init
{
return [self initWithFrame:CGRectZero];
}
After you fixed this, at least the viewDidLoad method in the third ViewController should work.
With regards to the second ViewController, could you please show the code you use to instantiate the ViewController?
Edit: I've made some changed to make sure initWithFrame: is always called upon initialization, just in case you create the instance using another method (initWithNibName:bundle: or init), now initWithFrame: has become the designated initializer.
Set class in Viewcontroller.
and then try.
Check the Object On which your are calling testAuthentication
May be you are calling testAuthentication on secondViewController's object , Just check and let us know
First time alone the viewController will come from viewDidLoad after that it does not call viewDidLoad instead it calls viewWillAppear. so you can code whatever you want in viewWillAppear.

Delegate not working

I have this code in my viewController:
- (GraphModel *)graphModel
{
if (!graphModel) {
graphModel = [[GraphModel alloc] init];
NSLog(#"graphModel = %#", graphModel);
}
return graphModel;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.graphView.delegate = [self graphModel];
NSLog(#"self.graphview.delegate = %#", self.graphView.delegate);
[self updateUI];
}
but the NSLog just says (null) for self.graphview.delegate
even though the NSLog in graphModel says that I successfully created an object. How can this be?
this is the code for the graphViewDelegate
#class GraphView;
#protocol GraphViewDelegate
- (double)yValueForGraphView:(GraphView *)requestor atPosition:(int)i withPrecision:(int)precision;
- (double)scaleForGraphView:(GraphView *)requestor;
#end
#interface GraphView : UIView {
id <GraphViewDelegate> delegate;
}
#property (assign) id <GraphViewDelegate> delegate;
#end
and then I have #synthesize delegate in graphView.m
Most likely guess: graphView is nil. Calling any method on a nil object has no effect and returns nil, and the .delegate is actually a call to the getter or setter as appropriate. I recommend you add:
NSLog(#"self.graphview = %#", self.graphView);
As a quick verification.