progressView doesn't work - objective-c

i want to show a progressView when the app is launching (with the splash screen) so, in the appDelegate .h file i declared a progressView :
UIProgressView *progView;
and in the appDelegate .m file i did this :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sleep(1);
progView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progView.progress = 0.75f;
// the rest..
}
i didn't see the progress bar in the splash screen, help please, thx in advance :)

You cannot influence the splash screen itself, it's only a static image.
What you can do however is to let your app load until you get the delegate message, then fire up some basic UI which shows your progress view and then do some heavy startup process in a background thread, updating your progress bar accordingly. When the thread has finished its work, call back to the main thread to start the real application.
Edit: Updated my answer to clarify some things
The application startup in iOS happens basically in 2 phases.
The operating system launches your application, the app sets up basic stuff, starts the run loop, etc. During this time the splash screen is shown. During this phase the application is not under the control of the programmer.
-application:didFinishLaunchingWithOptions is called. In this method you as a programmer may do some startup tasks, such as loading the database, connecting to some service, etc. During this phase you can influence the user interface and also show for example a progress bar. If you need to do this, create a background thread and do the setup work there.
Note: It does not work if you just put a progress bar on the UI and then do some stuff in the -application:didFinishLaunchingWithOptions: method, since the UI is not shown until after this method has returned. That's why you need to do the setup in a background thread.

is that all the code for progView? Cuz you haven't added it as a subview to anything, so how would you be able to see it? You need something like:
[splashView addSubview:progView];
frenetisch gave some reasonable explanation of the startup process of an IOS app, but it sounds like you need to do some basic investigation into this. It generally takes very little time before your didFinishLaunchingWithOptions is called and you can show your first view. But what things do you then need to do before your app is actually usable? You want to show a progress view so there must be SOMETHING that you plan to do that takes some time. It's while THAT is going on you need to show the progress view and somehow update it's progress.

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.

UIAlert during splashcreen

This is a two part question.
I have created a user agreement that the user must agree to when first launching the app (it is an alert with some information and agree/ do not agree button)
I call upon the method that creates this alert inside myAppDelegate.m and within the method
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
The problem is the alert pops up when the splash screen has finished loading and my first view comes up. I want this to happen during the splash screen. How would I do this?
The second question is When the users presses the "Do not agree button", I want them to exit the app so I have programmed it with
exit(0);
Is there a better way and will apple reject my app because of this?
Thanks in advance
1) You can't -- during the splash screen (your default.png) the app is loading into memory, and it cannot therefore execute any code, including presentation of a UIAlertView. That's why you don't see the alert until the splash disappears -- removal of the splash screen is the last thing that the app does before calling applicationDidFinishLoading:withOptions:.
What you can do is create a view controller that mimics your splash screen. This is easy -- you can even reuse default.png as a background if you want, though a better idea is just to present in this first view controller your agreement text and agree/disagree buttons.
As to your question re: use of exit(), it's best to avoid doing that. If the user refuses, you can simply do nothing. Of course, if you go the view controller route as I suggest, you can leave presented another opportunity for the user to agree.
Another thought is that Apple allows you to customize the EULA of your app when you upload a binary -- you could put it there and be covered.
Why not load our default.png as the background of you initial view and just handle the Alert in it's controller. you can always add another view or segue based on the answer.
The problem is the UIAlert blocks the Main thread, so it could stop your app from launching in time, and the process could be terminated.

UIViewController - mysteriously slow to load

I'm writing a tab-based universal app where one of the tabs takes considerably much longer to load than the rest (approximately 5s), and it locks down the main thread while doing it.
Now, this specific tab is an image gallery, so it could be expected to take a little while to load and display the images, however, the delay occurs before I instantiate any of my variables... (The image loading is done on a separate thread anyway...)
I create my subviews etc. in the viewDidLoad method, but the delay occurs somewhere after the init method and before the viewDidLoad method.
(The delay is present even if I comment out everything in the viewDidLoad method.)
The View Controller is initialized with a nib containing nothing but a UIScrollView and a UIImagePickerController...
Does anyone know what's being loaded/processed before the viewDidLoad method?
This is a problem with loading UIImagePickerController on the phone while being attached to the xcode harness. This creates a longer than normal delay. Try testing on the device without being connected to the xcode debugger.

A function called from different class does not work properly

I have a tabbar iPhone application in which tabbar is the root controller and each of the tabs is launching a separate webview window. Each time user taps one of the tabs I intercept the tap in AppDelegate and perform actions, one of which is displaying loading screen (an image in the tabbar view, with display toggled TRUE/FALSE).
My problem is, the loading screen is only displayed when all operations in AppDelegate are finished, which pretty much defeats the purpose of it. My guess is that I did some fundamental error designing this solution, but being a very inexperienced in iPhone programing I don't know how to fix it.
I'm accessing the function showLoading through iboutlets defined in AppDelegate:
[hv showLoading];
And this is what it does:
- (void) showLoading
{
loadingView.hidden = FALSE;
wheelHome.hidden = FALSE;
[wheelHome startAnimating];
NSLog(#"showLoad 1");
}
I'm seeing the "showLoad 1" immediately after bar is tapped, but loading image is only displayed when didSelectViewController exits.
My question - how can I make loading screen appear from AppDelegate OR is there a better way to display loading screen?
The problem is, that the UI is only updated when the event handling code returns to the run loop. You have two options:
Prepare for your long-running task (setup the UI) and then start the task by [myDownloader persormSelector:#selector(download) withObject:nil afterDelay:0];. The benefit of using performSelector:withObject:afterDelay: is that your code returns to the run loop, gets time to update the UI, and then immediately starts the task.
Design your long running tasks (downloading, ...) so that they perform in the background.
First of all, your tabbar should be controller by a UITabBarController and not the app delegate. See the Xcode TabBar template for implementation details.
Secondly, it sounds like you want an Application Startup Image. That is a static image that works like a splash screen if you app takes a little while to startup.

viewDidLoad is called only the first time

Maybe someone could tell me why when launch my app in the second time (after pressing the home button) the method viewDidLoad: is not being called?
On iOS 4 apps are no longer exited when pressing the home button. They are moved out of RAM, paused and then continued when you re-enter them, not launched again.
In iOS4 there is:
(void)applicationDidBecomeActive:(UIApplication *)application { }
Which is called when the application becomes active (out of background) you could call things from here that need to happen when you open the app.
Thanks
James
The second time you "launch" your application, in fact you are not launching but only re-activating (your application was in background). Your views are not reloaded.
As said in the previous answers :
You can detect it via (void)applicationDidBecomeActive:(UIApplication *)application and execute some code here (refresh HMI, refetch datas, etc...),
Or move your code to viewWillAppear