最近、Xcode でアプリを作成しました。2 つの画像が衝突すると、新しい画面が表示されます (これは良いことです)。ただし、ボタンを押して元のビューに戻すと、空白になります。なぜか教えてくれますか?どんなフィードバックでも大歓迎です。
最初の .h ファイルのコードは次のとおりです。
輸入
@interface ViewController : UIViewController {
IBOutlet UIImageView *image1;
IBOutlet UIImageView *image2;
}
@property (非アトミック、保持) UIImageView *image1; @property (非アトミック、保持) UIImageView *image2;
-(空)衝突;
@終わり
そして.mから:
「ViewController.h」をインポート
「newview.h」をインポート
@インターフェイス ViewController ()
@終わり
@実装ViewController
@synthesize image1, image2;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)イベント {
UITouch *mytouch = [[event allTouches] anyObject];
image1.center = [mytouch locationInView:self.view];
[self collision];
}
-(空)衝突 {
if (CGRectIntersectsRect(image1.frame, image2.frame)) {
newview *second = [[newview alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
}
2 番目の .h ([戻る] ボタンのあるコード) のコードを次に示します。
- (IBAction) 再試行: (id) 送信者;
そして.mから:
「newview.h」をインポート
「ViewController.h」をインポート
@interface newview ()
@終わり
@実装 newview
(IBAction)再試行:(id)送信者 {
ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil]; [self presentModalViewController:second animation:YES];
}