Question

I did some research on this, but alas, no answer. I have made a code machine that uses ASCII code. There are no errors or warnings. But when I run it I get this error: Thread 1: signal SIGBART. I think it has to do with UITextView "coded" but I don't know for sure. EDIT: The crash occurs when I click the "Encode" button ((IBAction)StartEncodeDecode).

All Output Log below. Can't believe I'm such a noob:

2013-08-28 14:00:57.086 Code Machine[2285:11303] -[CMViewController decodeEncode:]: unrecognized selector sent to instance 0x7151190 2013-08-28 14:00:57.155 Code Machine[2285:11303] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CMViewController decodeEncode:]: unrecognized selector sent to instance 0x7151190' * First throw call stack: (0x1c94012 0x10d1e7e 0x1d1f4bd 0x1c83bbc 0x1c8394e 0x10e5705 0x192c0 0x19258 0xda021 0xda57f 0xd96e8 0x48cef 0x48f02 0x26d4a 0x18698 0x1befdf9 0x1befad0 0x1c09bf5 0x1c09962 0x1c3abb6 0x1c39f44 0x1c39e1b 0x1bee7e3 0x1bee668 0x15ffc 0x1ded 0x1d15) libc++abi.dylib: terminate called throwing an exception (lldb)

End edit.

Code is below:

View Controller.m:

#import "CMViewController.h"
#import "CMAEncode.h"

@interface CMViewController ()
@property (weak, nonatomic) IBOutlet UITextView *toCode;
@property (weak, nonatomic) IBOutlet UITextView *coded; //I think the problem is with this text view.
@property (weak, nonatomic) IBOutlet UISwitch *onOrOff;

- (IBAction)StartEncodeDecode:(id)sender;




@end


@implementation CMViewController


- (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.
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
 replacementText:(NSString *)text
{

    if ([text isEqualToString:@"\n"]) {

        [textView resignFirstResponder];
        // Return FALSE so that the final '\n' character doesn't get added
        return NO;
    }
    // For any other character return TRUE so that the text gets added to the view
    return YES;
}
- (IBAction)StartEncodeDecode:(id)sender {

    NSString *finishedText;
    NSString *toCode = self.toCode.text;
    if (self.onOrOff.on == FALSE) {
        finishedText = [CMAEncode encodeText:toCode];
        self.coded.text = finishedText;
    } else { 
    }
}

@end

CMAEncode.m

#import "CMAEncode.h"

@implementation CMAEncode : NSObject 

+ (NSString *) encodeText:(NSString *)text {

    NSString *ToEncode = text;
    NSMutableString *Encoded = [NSMutableString string];
    int letter;
    NSUInteger i = 0;

    while (i < ([ToEncode length] - 1)) {
        letter = [ToEncode characterAtIndex:i];
        NSString *toAppend = [NSString stringWithFormat:@"%d|", letter];
        [Encoded appendString:toAppend];
        i = i + 1;
    }

    return Encoded;




}

@end

Here's the class where the error actually occurred. It's call main.m:

#import <UIKit/UIKit.h>

#import "CMAppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([CMAppDelegate class])); //This is where the error occurred.
    }
}

Thanks for helping!

Was it helpful?

Solution

Check in IB ui elements if you have an action performed IBAction linked with name "decodeEncode" . probably because you have linked it in IB (quick way is to right click on viewcontroller on IB & it will show everything). It seems you have some action being performed by the name "decodeEncode" but the method is not present in your CMViewController class. On side note If you do have this method implemented can you state where it is located ? put this method in your CMViewController.m file & check log

- (void)decodeEncode:(NSObject *)sender 
{

 NSLog(@"sending object >> %@", sender); 

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top