How to Show Second View Before Loading data from server and Run Indicator While Loading?
I made a player xib and go from the playlist xib to that one. The thing is that the player view has a bunch of data to capture and load. When you click the button on playlist to go to the player view, the player view WILL NOT be displayed until all the data is captured.
I want it to go to the player view immediately and then show an activity indicator on player page while it 开发者_Python百科loads the data.
How can I display the player xib file right on the button click, then load the data on there?
You can load your nib and activityindicator over it immediately and can use NSOperationQueue and NSInvocationOperation with appropriate selector which will perform your background task as this request will be run asynchronously. You can use KVO "isFinished" for this invocationOperation which will notify you when the operation is finished after which you can procceed with your further tasks.
I'd suggest you put only the most necessary UI elements into your xib and then start the lengthy loading process by implementing viewDidLoad in your viewcontroller (if you need to reload every time you switch to the player view) or loadFromNib (if you need it to only run once, when it's beeing first loaded from the xib).
Additionally you could move the loading into a seperate thread (see: NSThread) from which you post notifications to the NSNotificationCenter. Your viewcontroller could observe these notifications and update some status indicator to display the loading progress to the user.
精彩评论