返回UIApplicationMain(argc,argv,nil,NSStringFromClass([AppDelegate class]));线程1:SIGBART

时间:2014-11-10 00:56:48

标签: ios objective-c iphone xcode simulator

每当我尝试运行我的应用程序时,都会出现错误消息

viewController.h

#import "ViewController.h"

@interface ViewController ()

@end

viewController.m

@implementation ViewController

- (void)viewDidLoad {

    // Do any additional setup after loading the view, typically from a nib
    [super viewDidLoad];

    label.text = @"Number";

}

- (void)didReceiveMemoryWarning {

    // Dispose of any resources that can be recreated
    [super didReceiveMemoryWarning];

}


- (IBAction)numberButton {

    int number;
    number = arc4random() %100;

    // Turns the integer (number) into a string
    NSString *numberDisplay = [NSString stringWithFormat: @"%i", number];

    // Because the text has to be a string, i.e. an NSString
    label.text = numberDisplay;

}

- (IBAction)numButton {

    int number;
    number = arc4random() %100;

    // Turns the integer (number) into a string
    NSString *numberDisplay = [NSString stringWithFormat: @"%i", number];

    // Because the text has to be a string, i.e. an NSString
    label.text = numberDisplay;

}

- (IBAction)color {

    int color;
    color = rand() %4;

    switch (color) {
        case 0:
            label.textColor = [UIColor redColor];
            break;

        case 1:
            label.textColor = [UIColor purpleColor];
            break;

        case 2:
            label.textColor = [UIColor blueColor];
            break;

        case 3:
            label.textColor = [UIColor greenColor];
            break;

        default:
            break;
    }

}

- (IBAction)fontSize {

    int fontSize;
    fontSize = rand() %6;

    switch (fontSize) {
        case 0:
            [label setFont: [UIFont fontWithName:@"" size:5]];
            break;

        case 1:
            [label setFont: [UIFont fontWithName:@"" size: 15]];
            break;

        case 2:
            [label setFont: [UIFont fontWithName:@"" size: 25]];
            break;

        case 3:
            [label setFont: [UIFont fontWithName:@"" size: 35]];
            break;

        case 4:
            [label setFont: [UIFont fontWithName:@"" size: 40]];
            break;

        case 5:
            [label setFont: [UIFont fontWithName:@"" size: 45]];
            break;

        default:
            break;
    }
}

@end

我的.h有所有相同的动作。如果有拼写错误和/或连接错误,我已经检查并重新检查。还有什么可能是问题?

2 个答案:

答案 0 :(得分:0)

取出

int number; 
number = arc4random() %100;

在行动中。没有必要。

答案 1 :(得分:0)

我在测试项目中尝试您的代码并且运行良好。

我想也许你在联系上犯了一个错误。确认您的IBAction连接没有冗余连接。

这是我的代码(实际上我几乎没有改变):

#import "ViewController.h"


@interface ViewController()

@property (nonatomic,weak) IBOutlet UILabel * label;

@end

@implementation ViewController


@synthesize label;

- (void)viewDidLoad {

    // Do any additional setup after loading the view, typically from a nib
    [super viewDidLoad];

    label.text = @"Number";

}

- (void)didReceiveMemoryWarning {

    // Dispose of any resources that can be recreated
    [super didReceiveMemoryWarning];

}


- (IBAction)numberButton {

    int number;
    number = arc4random() %100;

    // Turns the integer (number) into a string
    NSString *numberDisplay = [NSString stringWithFormat: @"%i", number];

    // Because the text has to be a string, i.e. an NSString
    label.text = numberDisplay;

}

- (IBAction)numButton {

    int number;
    number = arc4random() %100;

    // Turns the integer (number) into a string
    NSString *numberDisplay = [NSString stringWithFormat: @"%i", number];

    // Because the text has to be a string, i.e. an NSString
    label.text = numberDisplay;

}

- (IBAction)color {

    int color;
    color = rand() %4;

    switch (color) {
        case 0:
            label.textColor = [UIColor redColor];
            break;

        case 1:
            label.textColor = [UIColor purpleColor];
            break;

        case 2:
            label.textColor = [UIColor blueColor];
            break;

        case 3:
            label.textColor = [UIColor greenColor];
            break;

        default:
            break;
    }

}

- (IBAction)fontSize {

    int fontSize;
    fontSize = rand() %6;

    switch (fontSize) {
        case 0:
            [label setFont: [UIFont fontWithName:@"" size:5]];
            break;

        case 1:
            [label setFont: [UIFont fontWithName:@"" size: 15]];
            break;

        case 2:
            [label setFont: [UIFont fontWithName:@"" size: 25]];
            break;

        case 3:
            [label setFont: [UIFont fontWithName:@"" size: 35]];
            break;

        case 4:
            [label setFont: [UIFont fontWithName:@"" size: 40]];
            break;

        case 5:
            [label setFont: [UIFont fontWithName:@"" size: 45]];
            break;

        default:
            break;
    }
}

@end