Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:58:17+00:00 2026-06-08T08:58:17+00:00

I’m new to objective-c and I’ve gone through a tutorial to build a ‘tip

  • 0

I’m new to objective-c and I’ve gone through a tutorial to build a ‘tip calculator’ app for iPhone. I’m using Xcode 4.3.3 and I have checked all the code and it is identical to that in the tutorial (which I’m sure is correct). I have been trawling through site trying to find someone who had the same problem and I have not been able to fix it so I appreciate any help. This is the message that appears whenever I try to run the app.

2012-07-23 14:22:01.021 Tip_Calculator[554:f803] -[ViewController
initWithCoder:]: unrecognized selector sent to instance 0x68a3130
2012-07-23 14:22:01.025 Tip_Calculator[554:f803] * Terminating app
due to uncaught exception ‘NSInvalidArgumentException’, reason:
‘-[ViewController initWithCoder:]: unrecognized selector sent to
instance 0x68a3130’
*
First throw call stack: (0x13c8022 0x1559cd6 0x13c9cbd 0x132eed0 0x132ecb2 0x234135 0x333c6e 0x333383 0x233cad 0x333c6e 0x33367b
0x333383 0x233105 0x43ceef 0x43d03e 0x11d7a 0x11ff8 0x1117f 0x20183
0x20c38 0x14634 0x12b2ef5 0x139c195 0x1300ff2 0x12ff8da 0x12fed84
0x12fec9b 0x10c65 0x12626 0x253d 0x24a5) terminate called throwing an
exception(lldb)

This is the area flagged in main.m:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {        return UIApplicationMain(argc, argv, nil,     NSStringFromClass([AppDelegate class]));    }
}

I have checked all the interface connections and they are fine. I have also added an exception breakpoint and this error showed up :

2012-07-23 20:49:53.633 Tip_Calculator[2067:f803] -[ViewController
initWithCoder:]: unrecognized selector sent to instance 0x68c09c0
(lldb)

This is the error log that is shown:

Tip_Calculator`start:
0x2470:  pushl  $0
0x2472:  movl   %esp, %ebp
0x2474:  andl   $-16, %esp
0x2477:  subl   $16, %esp
0x247a:  movl   4(%ebp), %ebx
0x247d:  movl   %ebx, (%esp)
0x2480:  leal   8(%ebp), %ecx
0x2483:  movl   %ecx, 4(%esp)
0x2487:  addl   $1, %ebx
0x248a:  shll   $2, %ebx
0x248d:  addl   %ecx, %ebx
0x248f:  movl   %ebx, 8(%esp)
0x2493:  movl   (%ebx), %eax
0x2495:  addl   $4, %ebx
0x2498:  testl  %eax, %eax
0x249a:  jne    0x00002493               ; start + 35
0x249c:  movl   %ebx, 12(%esp)
0x24a0:  calll  0x000024b0               ; main at main.m:14
**0x24a5:  movl   %eax, (%esp)**
0x24a8:  calll  0x000033ca               ; exit
0x24ad:  hlt    
0x24ae:  nop    
0x24af:  nop 

I put asterisks around the flagged area. The same error is shown whether there is an exception breakpoint or not.

I am using storyboard, here is the .h file of the ViewController:

#import <UIKit/UIKit.h>

@interface ViewController : NSObject
{
//outlets
IBOutlet UITextField *billField;

IBOutlet UITextField *tipFieldTen;
IBOutlet UITextField *tipFieldFifteen;
IBOutlet UITextField *tipFieldTwenty;
IBOutlet UITextField *tipFieldCustom;
IBOutlet UITextField *totalFieldTen;
IBOutlet UITextField *totalFieldFifteen;
IBOutlet UITextField *totalFieldTwenty;
IBOutlet UITextField *totalFieldCustom;
IBOutlet UILabel *customPercentLabel;
IBOutlet UISlider *customPercentSlider;

NSString *billTotal;
}
-(IBAction)calculateTip:(id)sender;



@end

And here is the .m file:

#import "ViewController.h"

@implementation ViewController

- (void)awakeFromNib; 
{
[billField becomeFirstResponder]; //display keyboard for billField
}

-(IBAction)calculateTip:(id)sender
{
static BOOL toggle = YES;

if (toggle)
{
    toggle = NO;
    NSString *billFieldText = billField.text;

    float newTotal = [billFieldText floatValue];
    float customTipPercent = customPercentSlider.value;

    if(sender ==billField)
    {
        if (billFieldText.length <billTotal.length)
            billTotal = [NSString stringWithFormat:@"%.02f", 
                         newTotal / 10];
        else
            billTotal = [NSString stringWithFormat:@"%.02f",
                         newTotal * 10];

        billField.text = billTotal;

        newTotal = [billTotal floatValue];

        float tenTip = newTotal * 0.10;
        float fifteenTip = newTotal * 0.15;
        float twentyTip = newTotal * 0.20;

        tipFieldTen.text = [NSString stringWithFormat:@"%.02f", tenTip];
        tipFieldFifteen.text = [NSString stringWithFormat:@"%.02f", fifteenTip];
        tipFieldTwenty.text = [NSString stringWithFormat:@"%.02f", twentyTip];

        totalFieldTen.text = [NSString stringWithFormat:@"%.02f", newTotal + tenTip];
        totalFieldFifteen.text = [NSString stringWithFormat:@"%.02f", newTotal +   fifteenTip];
        totalFieldTwenty.text = [NSString stringWithFormat:@"%.02f", newTotal + twentyTip];
    }
    else if (sender == customPercentSlider)
    {
        int percentage = (int)(customTipPercent * 100);
        customPercentLabel.text = [NSString stringWithFormat:@"%i%%", percentage];
        float newSliderValue = ((float) percentage) / 100;
        customPercentSlider.value = newSliderValue;
        customTipPercent = newSliderValue;
    }
    float customTip = customTipPercent * newTotal;
    tipFieldCustom.text = [NSString stringWithFormat:@"%.02f", customTip];
    totalFieldCustom.text = [NSString stringWithFormat:@"%.02f", customTip + newTotal];
}
else
{
    toggle = YES;
}

}



@end

Any help would be much appreciated as I’m new to objective-c.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:58:19+00:00Added an answer on June 8, 2026 at 8:58 am

    You have

    @interface ViewController : NSObject
    

    this should probably be:

    @interface ViewController : UIViewController
    

    Reason:

    So your ViewController class is currently inheriting from NSObject, which does not implement initWithCoder. In fact, this method call is part of the NSCoding protocol, which UIViewController adopts.

    Background:

    The error you received is basically saying that an object of the class ViewController was sent a selector, or ‘message’, initWithCoder, but it didn’t have an implementation of that method. So there are two things you would generally do to track this down:

    1) Check if you are sending that message anywhere in your code, and then whether the object that receives it is of a class that should recognise that method. You also have to consider that method being called from UIKit, etc frameworks, which makes this a bit more difficult.

    2) If the above looks ok, then you have to consider that perhaps while your code assumes an object is one type, it might actually be a different one, hence this error occuring.

    Consider this code:

    NSArray *anArray = [[NSArray alloc] initWithObjects:@"aString", nil];
    NSNumber *aNumber = [anArray objectAtIndex:0];
    BOOL isEqual = [aNumber isEqualToNumber:[NSNumber numberWithInteger:42]];
    

    This will compile without warning, but when run will cause an exception – because it assumes the object in the array is NSNumber, but in fact it is NSString:

    * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFConstantString
    isEqualToNumber:]: unrecognized selector sent to instance 0x6cbfc’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.