0

I have two buttons on a action sheet, when I click one of the button, it will display all the students record in another view. All these records need to be retrieved from DB. Currently I put the logic of retrieve the record in the viewwillAppear method, But after I click the button the screen froze there for a few seconds then the student list will displayed.

Per my understanding my logic of retrieve the record was in viewWillAppear method in student list view. After I click the button , it should to directly to student list view , then in the student list view it will try to load the data. But now after I click the button why it froze in the action sheet? Or are there any other place that I can put the load record logic in so that it will not froze in the previous action sheet After I clicked the button.

Maksim
  • 2,054
  • 3
  • 17
  • 33
user1330526
  • 151
  • 1
  • 3
  • 10

1 Answers1

0
  1. If you're going to post to SO, you always should include your existing code. I'd suggest you update your question accordingly. See the FAQ.

  2. When you say that it "froze", do I infer that you're saying that there was a delay before you saw your new view with the data, but that it eventually appeared? If so your task is how to identify where the delay took place. So, I'd suggest you start inserting NSLog statements in the various methods so you can identify where exactly the delay is taking place. Did it take a long time for the new view to be loaded? For the data to be retrieved? Etc. Until you narrow down the problem, identify the source of the delay, you won't be able to solve it. You need to develop the skills to diagnose and troubleshoot your problems. By the way, if you're still having problems figuring out how to diagnose your code and the NSLog doesn't help, you can also refer to Apple's documentation on debugging and stepping through your code. You should only post here after you've narrowed down precisely where in your code the problem is manifesting itself.

  3. Third, most people load their data for their new views in viewDidLoad, not viewWillAppear; if you ever went to a subview of your student list view and then came back to your student list (i.e. the student list view reappeared, i.e. viewWillAppear will trigger again), would you really want to load the data again, even though you've already loaded it? Probably not. I know you might not have another view that you're loading after you load your student list view, but you may eventually (e.g., a student detail view), so good practice is that you should load your view's data in viewDidLoad (which will trigger only the first time the view is initially loaded).

Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044