0

I make a game that has 2 scenes (first-welcome screen with "start game" button, second - is the game") Game is simple: head-picture is trying to prevent collions with bullets(represented as uiimageviews in NSMutableArray *bullets) with the help of -(void)touchesMoved:withEvent:. If it collides UIAlertView appears to get user's choise: repeat or go to wellcome-scene. If we go to the game-scene first time then everything is OK.

The problem is when we go to the game-scene next time. the property bullets after initiation in viewDidLoad shows its count as 3(as it should), but latter it shows bullets.count == 0; I don't know how is it possible - I initiate this array in method that calls only in viewDidLoad. And in the first time everything works properly.

P.S. duaring code I don't use propertyName, only self.propertyName.

P.P.S I suggest reason in [UIView commitAnimations] - that's how I make bullets animation. If I //hide it. evetything is OK. But without animation it looks poor.

1 Answers1

0

Instead of calling the method in viewDidLoad, try calling it in viewDidAppear to set the count to 3 each time the view appears, because it should only be loaded into memory once, but viewDidAppear is called each time the view will show.

Andrewp97
  • 15
  • 3
  • in storyboard scene viewDidAppear and viewDidLoad calls the same times (if app doesn't interrupted by ios). So why do you think it should help? – user2380791 Jun 23 '13 at 23:25
  • Because when I use UITableView and have it load the cells from an array in core data, calling [self.tableView reloadData] does not refresh the data when placed in viewDidLoad, but it is refreshed if I place it in viewDidAppear. This way, when I activate a modal view controller and add a new item to the database, when I dismiss the modal, the table has refreshed. So, at least as far as I know (please correct me if I am wrong) viewDidAppear is called every time that view is about to be shown on screen, and viewDidLoad is called when the view is loaded into memory. – Andrewp97 Jun 24 '13 at 10:27
  • well)) there is viewWillAppear to called when view "is about to be shown" =) and if you want to reloadData of tableView it is realy better to use not even viewDidAppear, but viewWillAppear. becouse if you have dataSource of 1000 elements user firstly see last dataSource for a moment. – user2380791 Jun 24 '13 at 12:46
  • That makes sense, thanks. I will change my app to use viewWillAppear now that you said that. – Andrewp97 Jun 28 '13 at 00:27