How to deal with time delay when a SWTableView is being loaded? - objective-c

In an iPhone game, I want to display a CCLayer containing a SWTableView when the user taps on the screen. The table mainly contains images.
Now the problem is, on an old device, say ipod touch 2g running iOS4.x, It takes about 1 second or even more to load the table (because it is loading images) before it is displayed on the screen.
I tried to add a spinner view to indicate that the table is being loaded. But the spinner does not get printed on the screen until the table is displayed.
Does anyone have a good strategy to deal with this delay? Or is it at lease possible to do anything between a touch event and the loading of the table?
Any help will be greatly appreciated! Thanks!

If you subclass SWTableView, you can implement the init and viewDidLoad methods. In init, put a spinner in the middle of the view, and in viewDidLoad remove the spinner. If that doesn't work you may want to try subclassing CCLayer in the same way.

Related

Slow UITabBar item loading

There is the problem in my project, this problem can bring lots of unpleasant feelings for customer.
So app is basically ground on UITabBarController and when I want to load one of UIViewController it loads too long (~ 1.5s in first launch and after switching there is seeing pause) - its very bad for user experience, as you know.
So I want to know some way to preload this section before user want to enter there (section doesn't loads first). There are few questions which can be the same with first glance but I don't want to have a solution like "spinner while loading".
If anybody knows elegant solution I'll very thankful.
Alexey
To me this sounds like you do lot of work in either your init method, the viewDidLoad or the viewWillAppear method of your UIViewController.
On the first load I don't know an answer, but you could load the other view controllers in the UITabBarController in a background thread so they are loaded when you tap them.
EDIT:
On first load you could use a very simple start screen and load the first screen also on the background thread. But then you would have to add a new view.

Two view controllers (with nibs) acting on the screen at the same time

Just as a disclaimer, I am an iOS beginner, in a pretty unique position. I'm an intern learning on the job, with a hard deadline for a test app, with specific specs. So I unfortunately don't have the luxury of learning all that I should about xCode and objective C.
Anyways, I am trying to create a navigation menu similar to the iPad's slide out menu. I've looked at plenty of sample code given in response to questions like this in the past. It all works perfectly fine, but I can't understand all of what they're doing. I think this results from being fairly bewildered by view controllers and delegates. And, since I'm supposed to be writing this all by myself, I can't just build off of their existing code.
My plan for this working is to have one main view controller, containing the navigation menu in a table view. This is hidden behind a normal UIView, until a button is pressed, at which point the normal UIView slides offscreen enough to reveal the menu. Upon selection of a menu item, the normal UIView would slide back to its original position, and be replaced by the relevant UIView, controlled by its view controller. In other words, clicking on the menu item relating to "Home" would load the homeViewController.xib, controlled by the homeViewController. This would be loaded in that normal UIView subview, on top of the tableView.
I'm able to load a view in that normal UIView as a result of a button press.
homeViewController *_homeViewController = [[homeViewController alloc]initWithNibName:#"homeViewController"];
[self frontView] = _homeViewController.view;
There may be some syntax errors in that code, since its from memory. I'm not able to access the computer with my code on it at the moment, but that's the general gist. Basically, that places the home view nib on the frontView (that normal UIView that's over the table view), but its not connected to homeViewController. Or at least I think that's the issue, when I press a button, that's correctly connected between the nib and the homeViewController.h, and only set to NSLog in the .m file, the application crashes.
Any idea how to connect this nib to its viewController when displayed in this way? Or, to create the nib in IB, without the associated .h and .m files, and use the main view controller as the homeViewController as well? Or, if my logic is inherently flawed, what SHOULD I do? Something with NavigationControllers?
EDIT:
I also tried a new approach- changing homeViewController's file owner to viewController, and connecting the button on homeViewController's action to viewController. This too caused a crash upon pressing the button. I really think the issue is with having multiple view controllers acting on screen at once, or having multiple views from separate nibs, controlled by one view controller on screen at once.
I suspect that your immediate problem is that _homeViewController is being freed as soon as you leave whatever method that code is in. To fix this, create a strong property in this class that holds the _homeViewController for as long as its view is needed and allocate it to that property rather than a local variable. That way, buttons (or whatever) that are part of that view still have a valid controller object backing them.
In the long run, pushing or presenting view controllers when you need the screen to change is a much better strategy but, as I said, the immediate problem.... :)

Cycling through same scene on storyboard

I have a single storyboard scene that will be displayed over and over again as the user pages through data fetched from a database. When the user hits the next button, the scene segues to itself and displays the next record.
The code may not be pretty but the end result looks right, with the navigation controller handling the animation. But now that I've got it working, I'm sure it's not the right approach - I'm using a navigation controller to pop this same scene over and over, when there's no reason for the popped scene to be held in memory (data is retrieved each time it's pushed or popped).
Curious whether anyone else has done something similar and hoping for some advice on what the best approach may be. I've thought about simulating the look of the scene being popped and pushed by animating a subview - is there a third, better option? Thanks.
UPDATE
Testing has proven that the navigation controller is handling its own memory management just fine.
The view I'm working with isn't that demanding memory-wise. If anyone with a similar query has views that are, and are concerned about exceeding memory limit - this would be a good link to check out:
Memory Consumption of UINavigationController

add a subview to a not-showed uiview

I'm dealing with a weird problem: I've got a UIViewController to handle a list of items to download via inapp purchase.
When a user choses the product to buy, all the purchase flow begins. At this particular moment, I push a UILabel and a progress bar to display the current state of the download.
If, before that, a user choses to go in another part of the application (i.e. by tapping an item form the tab bar menu ), the application continues the purchasing process from there (that is reduced down to saying yes to a couple of dialog boxes and inputing the itunes store account credentials).
The process (that is attached to a background thread) runs smoothly till the end of it, but if the user comes back to the store view the UILabel and the progress bar are not show, I mean, they are initialized and running but they're not visible.
Is there a right way to behave in that circumstance?
Do I have to force the refresh of the view, or do I have to remove'em from the superView and push'em back again?
thank in advance,
hope I'd be clear enough, otherwise don't be afraid to ask, I'll be glad to
explain myself in a more deep and clear way.
-k-
Without a code it is difficult to give you the exact solution.
A possibility is that when you moved out from the original UIViewController the system did unload the view on that controller. It is possible that with this unload the progress bar and label were not destroyed (because over-retained by your view controller or not nil-ed in the viewDidUnload method) but when you entered in the view controller again the view was reloaded from scratch (typically from the nib) with new progress and labels.
So it is correct that you retained the progress bar and label (even if there are better ways to achieve the same result) but you must add them to the view controller view in the viewDidLoad method. A typical way to do this is to store a "active" progress bar in a dictionary and when the view is reloaded from the nib it must be added to it. As soon as the download finish you can remove the progress from both the dictionary and the view. There are other ways to accomplish the same result, so my suggestion is just to give you an idea.
So in order to see if my answer is correct, you must check the viewDidUnload method, add a breakpoint on it and see, once it has been triggered and when you come back to your original view, if the progress bar has disappeared or not.
Hello Holographix u havnt posted any code so it would be difficult to tell
well it seems like the object of Uilabel and progress bar are getting released the time u comes back to the view.

Manipulate UI from AppDelegate

I am a newbie in all this as will be apparent really soon.
I am using the iOS: Application: Tabbed application template. I have placed a UIImageView in the first view and two standard rounded buttons. One button is attached to an action in the FirstView Controller which places a picture into the UIImageView. The second button is attached to an action in the AppDelegate which calls a method in the FirstViewController which in turn places a second picture into the UIImageView.
The AppDelegate method does not replace the picture. It doesn't crash… it just does not seem to do anything.
How can I manipulate the view in the First and Second View Controller from the AppDelegate?
#dasdom
Well that's one issue explained. I've been reading the theory of MVC and trying to put it into practice now. Short version is I am trying to write a Battleship app for practice. Was planning on using the first screen to setup the game pieces, prefs, etc.. and use the second screen for actual game play.
I've created another class to use as my "brain center" but I ran into the same issue of not being able to manipulate anything on the screen for the first or second views. (That's why I tried the appDelegate).
That's my life story right now… can you throw some pointers my way on how to proceed and how to solve my one of many problems?
First you shouldn't do that. The AppDelegate should only be responsible for bringing the first view onto the screen.
Second you should have a look into the Model-View-Controller design pattern. Search for it in your preferred search machine.
But I you really still want to do that you should have a look into delegation and/or notifications. For example you could send the First View Controller a notification from the AppDelegate to change the image.