Sergnsk
Sergnsk

Reputation: 3303

How to "reset" to the starting view?

I have my first sample iPhone application - some version of TicTacToe. It's working fine but only one time %) I cant figured out how to reset my view in game to starting position.

I followed Formic game example from "iPhone Cool Projects" book. I create Controller, then View and mark X or O signs in my game via UIImageView which I add as Subview to my View. That's ok and it works fine. But now I want to remove all this X and O's and start new game - and cant understand how to clear the screen. Btw this game example from the book didn't have resetGame method as well :(

I tried release view but I think it wrong - it clear screen but I got memory errors later and cant initialize board again. Tried call viewDidLoad - nothing. What is the best practice for this?

Thx!

Upvotes: 0

Views: 272

Answers (1)

TechZen
TechZen

Reputation: 64428

To clear the Xs and Os UIImageViews, just send them the -[UIView removeFromSuperview] message. This will remove them from their superview and the visible UI. If they are not retained by another object they will be removed from memory as well.

You only use release as a memory management tool. You never use it remove visible elements from the UI or any other functional task.

Upvotes: 1

Related Questions