-5

私はこのプロジェクトに取り組んでおり、4-4 の赤い四角を画面上でバウンスさせようとしていますが、このコードを実行するたびに Thread 1:signal SIGABRT というスレッド エラーが表示されます。私がやろうとしていることを手伝ってくれる人はいますか?ここに私のコードがあります

#import <UIKit/UIKit.h>

@class home;

@interface ViewController : UIViewController{
    ViewController* home;
    CGFloat rhx;
    CGFloat rhy;
    CGFloat red_direction_x;
    CGFloat red_direction_y;
}

@property CGFloat rhx;
@property CGFloat rhy;
@property CGFloat red_direction_x;
@property CGFloat red_direction_y;
@property ViewController* home;

@end

#import "ViewController.h"

@implementation ViewController

@synthesize rhx,rhy, red_direction_x, red_direction_y, home;

-(void)event:(NSTimer*)timername{
    UIView* redhead = [[UIView alloc]initWithFrame:CGRectMake(rhx, rhy, 4, 4)];
    redhead.backgroundColor = [UIColor redColor];
    [self.view addSubview:redhead];
    if (rhx >= self.view.bounds.size.width) {
        red_direction_x = -4;
    } else if (rhx <= 0) {
        red_direction_x = 4;
    }

    if (rhy <= 0) {
        red_direction_y = 4;
    } else if (rhy >= self.view.bounds.size.height) {
        red_direction_y = -4;
    }

    rhx += red_direction_x;
    rhy += red_direction_y;
}

- (void)viewDidLoad {
    self.home = [[ViewController alloc] init];
    red_direction_x = 4;
    red_direction_y = -4;
    rhx = 4;
    rhy = 4;

    [super viewDidLoad];

    [NSTimer scheduledTimerWithTimeInterval:0.1
                                 target:self
                                 selector:@selector(event)
                                 userInfo:nil
                                 repeats:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
4

2 に答える 2

1

コードの明らかなバグの 1 つは、 のセレクターでタイマーを設定してeventいるが、 という名前のメソッドがないことですevent。代わりに、という名前のメソッドがありますevent:。結腸は世界にすべての違いをもたらします。

タイマーを変更して、セレクタ パラメータが渡されるようにします@selector(event:)

補足として、event:メソッドは新しいサブビューを追加し続けます。あなたの目標が何であるかはわかりませんが、既存の 1 つのビューを移動したいだけかもしれません。

于 2013-06-29T23:07:57.807 に答える
1

Xcode で、ブレークポイント ナビゲーターに移動し、すべての例外を追加します。例外が見つかった場所でコードにブレークポイントを設定します。

ここに画像の説明を入力

于 2013-06-29T23:27:45.927 に答える