线程1信号SIGABRT

时间:2013-08-27 10:54:36

标签: iphone objective-c cocoa-touch iboutlet

我对此做了一些研究,但唉,没有答案。我已经制作了一个使用ASCII码的代码机。没有错误或警告。但是当我运行它时,我得到了这个错误:线程1:信号SIGBART 。我认为这与UITextView“编码”有关,但我不确定。 编辑:当我点击“编码”按钮((IBAction)StartEncodeDecode)时发生崩溃。

以下所有输出日志。我不敢相信我是一个菜鸟:

  

2013-08-28 14:00:57.086 Code Machine [2285:11303] - [CMViewController decodeEncode:]:无法识别的选择器发送到实例0x7151190   2013-08-28 14:00:57.155 Code Machine [2285:11303] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [CMViewController decodeEncode:]:无法识别的选择器发送到实例0x7151190'   * 第一次抛出调用堆栈:   (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调用抛出异常   (lldb)

结束编辑。

代码如下:

查看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

这是实际发生错误的类。它叫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.
    }
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

如果您执行了与名称“decodeEncode”关联的IBAction,请检入IB ui元素。可能是因为你已经在IB中链接它(快速的方法是右键单击IB上的viewcontroller&amp;它将显示所有内容)。看起来你有一些名为“decodeEncode”的动作,但你的CMViewController类中没有这个方法。侧面说明如果您确实已实施此方法,您可以说明它的位置吗?将此方法放入CMViewController.m文件&amp;检查日志

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

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

}