当前位置: 动力学知识库 > 问答 > 编程问答 >

uiviewcontroller - Need right direction for reload application by action

问题描述:

My scenario is a UIView Controller displays different subview programmatically... Like a game board. Now I'm in a incredible situation:

I can't find a way to reload application after the game is finish!? What I would like to do is after terminate scenario clic on IBAction for star new game. My doubt is about ViewDidLoad or call Main.

网友答案:

try moving your code from viewDidLoad into a new function like -(void)startGame or -(void)refreshViews: and call that function whenever you want to reload your view. even in viewDidLoad you can load your view using this function.

-(void)viewDidLoad
{
[super viewDidLoad];

[self startGame];


}

remember if you are creating allocating and add some of your subviews outside this function then they will remain visible untill and unless yu remove them from superView before calling startGame.

网友答案:

I solved it with this code:

(IBAction)newGame:(id)sender{


    UIView *parent = self.view.superview;
    [self.view removeFromSuperview];
    self.view = nil; // unloads the view
    [parent addSubview:self.view];


}
分享给朋友:
您可能感兴趣的文章:
随机阅读: