2012-12-19 67 views
0

我最近用Xcode創建了一個應用程序。當兩個圖像相撞時,它會將我發送到一個新屏幕(這很好)。但是,當我按下按鈕將我返回到原始視圖時,它將變爲空白。你能告訴我爲什麼嗎?任何反饋讚賞。回去之後的空白篩選

這裏是從第一h文件的代碼:

進口

@interface的ViewController:的UIViewController {

IBOutlet UIImageView *image1; 
IBOutlet UIImageView *image2; 

}

@屬性(非原子,保留)的UIImageView *此搜索; @property(nonatomic,retain)UIImageView * image2; (空)碰撞;(空)碰撞;(空)碰撞;

@end

而且從.M:

進口 「ViewController.h」

進口 「newview.h」

@interface視圖控制器()

@ end

@implementation ViewController

@synthesize image1,image2;

- (無效)touchesMoved:(NSSet中*)觸摸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]; 


} 

}

這裏是第二個.h(帶回去按鈕的那個)代碼:

  • (IBAction)retry:(id)sender;

,並從.M:

進口 「newview.h」

進口「視圖控制器。H」

@interface NewView的()

@end

@implementation NewView的

  • (IBAction爲)重試:(ID)發送方{

    的ViewController *秒= [ [ViewController alloc] initWithNibName:nil bundle:nil]; [self presentModalViewController:second animated:YES];

}

回答

0

空白屏幕是從(IBAction爲)重試另一個模態的視圖:(ID)發送者。

你應該使用[self dismissModalViewControllerAnimated:YES];在(IBAction)重試中:(id)發送者返回到前一個屏幕而不是呈現另一個模態視圖。

+0

非常感謝!它工作得很好! – user1510082