I am trying to add some titles to my project. So, when my app gets loaded it should show my title screen with activity indicator spinning and after 3seconds it should push the navigation controller. Basically I will have an image on the first view controller. So, in IB I added an image view and set the image. Please help me guys how to load second view controller after the first view controller gets loaded..
Basically please tell me how to push navigation controller after particular time delay without any buttons or any other controls in it..
Thanks for all your time..
EDIT
- (void)viewDidLoad {
[super viewDidLoad];
[indicator startAnimating];
timer=[NSTimer scheduledTimerWithTimeInterval: 3.0 target:self selector:#selector(loadNextView) userInfo:nil repeats: YES];
}
-(void)loadNextView
{
TabBarControllers *tabBar=[[TabBarControllers alloc]initWithNibName:#"TabBarControllers" bundle:nil];
[self.navigationController pushViewController:tabBar animated:YES];
[indicator stopAnimating];
}
There's also lots of iPhone example code that uses an NSTimer to call any method on any object after a specified delay. Just create a method to stop the activity indicator and push your next controller, and call that method via a 3 second NSTimer after starting the activity indicator in your first view.
Take a look at the NSObject's performSelector:withObject:afterDelay: method. You should able to specify 3 seconds delay to perform the action.
Related
I have a ViewController that takes time to load its views. When I run Instruments, I see from the home screen, if I tap on the icon that pushes that view controller onto the stack, it's half laying out the views, and half getting the data for the views. I tried adding an activity indicator to display on the home screen over the button when the button is pressed to push the LongRunningViewController onto the stack. So I basically do this:
- (IBAction)puzzleView:(id)sender {
dispatch_async(dispatch_get_main_queue(), ^{
[self.activityIndicator startAnimating];
});
PuzzleViewController *detailViewController = [[[PuzzleViewController alloc] init] autorelease];
[self.navigationController pushViewController:detailViewController animated:YES];
[self.activityIndicator stopAnimating];
}
The home screen lags while pressing the button, and then loads the view. I'm trying to show the activity indicator while the other screen is preparing to be pushed (or at least that's the way I think it works). The activity indicator does not show however. I'm wondering if this can be done? Or do other apps push their ViewController, and then on that screen, they have the activity indicators showing the loading of their different resources?
When you say that it takes time to get the data for the views, I assume you mean that the PuzzleViewController does something non-trivial somewhere like viewDidLoad.
So let's say it is in viewDidLoad. Then you can do this:
-(void)viewDidLoad
{
[self.activityIndicator startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
//do something expensive
[self doSomethingExpensive];
//dispatch back to the main (UI) thread to stop the activity indicator
dispatch_async(dispatch_get_main_queue(), ^
{
[self.activityIndicator stopAnimating];
});
});
}
This will mean that the expensive operation will be put on a background thread and won't block the loading/showing of the view controller.
This approach is showing the requested view immediately when the user pushes the button, and showing progress on that screen. I think it's more common this way than to show an activity view while loading contents before presenting the view. This also buys you a little bit more time; your long operation can be running in the background during the transition animation!
The reason your activity view isn't showing the way you're doing it is that you're doing it all on the UI thread; using dispatch_async to the main queue from the main queue won't accomplish anything because your block won't have a chance to run until the run loop completes.
I want to display dynamic UIAlertView and Indicator within it when data is loading from web-service.
Also I don't want any button on UIAlertView. And it will be stopped automatically when data will be loaded successfully.
How can I implement it.?
Just declar UIAlertView and then your activity indicator, make indicator a sub view to alert view and then when your data has been loaded from web service dismiss with this instance method
– dismissWithClickedButtonIndex:animated:
If you are using WebView then write startAnimating ActivityIndicator in ViewDidLoad and this delegate method will call by itself when your data will be loaded
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[ActivityIndicator stopAnimating];
}
Hope it helps.Thanks :)
Then use MBProgress HUD or SVprogress HUD
https://github.com/jdg/MBProgressHUD
I have two issues with activity indicator:
1. Activity Indicator not showing up on UIViewController
I have activity indicator added in .xib file. On button click it should start animating. and when response from server is received, before going to next page it should stop animating.
I am doing it as follows:
activityIndicator.hidden = NO;
[activityIndicator performSelector:#selector(startAnimating) withObject:nil afterDelay:0.1];
[self.view bringSubviewToFront:activityIndicator];
....rest of code here....
activityIndicator.hidden = YES;
[activityIndicator stopAnimating];
Activity Indicator not showing up on UITableView
For table view I am doing it same way but on didselectrowatindexpath...
For tableview I also tried adding activity view to cell accessory, but still not showing up
In both cases activity Indicator is not showing up.
Please help
Thanks
If all this code is in one method or in response to one event, then none of the changes to the views are going be visible until you return to the event loop. You set the activityIndicator.hidden to NO and then set it again to YES before the UI has an opportunity to even refresh.
You also apparently stop the animation before you start it.
What you need to do is make the activity indicator visible here and start its animation. Then schedule the work to be done (start an asynchronous network connection, or put some work into a queue, or whatever it is you need to get done) and return from this method so that the UI can refresh, the indicator can be drawn, and the animation can actually start.
Then later at some point after the work is complete, you can hide the indicator and stop the animation. But you can't do all of that on the main thread within one single turn of the event loop. None of your changes will be visible because no drawing at all will happen here while this method is executing (assuming this is on the main thread)
I hope that makes sense?
Now I modified the code to this:
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
[self performSelector:#selector(saveClicked) withObject:nil afterDelay:0.1];
[self.view bringSubviewToFront:activityIndicator];
and it worked :)
May be, in tableView, instead of self.view , it will be self.navigationController.view ??
I want to write a ios app that can pop up a full screen windows (e.g. to play a video) at a specify time, it seems UILocalNotification cant' help. anybody have any idea?
You can present a modalView while at the same time, removing the UIStatusBar
From within your view controller, you can call
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
Which will display the specified view controller on top of the current one modally.
To do this on a timer interval (which is what I think you're implying you want to do?) you'd do the following:
-(IBAction)showModalWithDelay {
[NSTimer scheduledTimerWithTimeInterval:.06 target:self selector:#selector(showModal) userInfo:nil repeats:NO];
}
-(void)showModal {
[self presentModalViewController:modalViewController animated:YES];
}
I am developing a Window Based app for iPhone. I use Interface Builder to build Interface. I want to call a new screen with a Button Action. How can I call the screen with Button action ?
By pushing the new controller onto the top of the stack of windows. For example:
EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:#"EnterName" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newEnterNameController animated:YES];
Apple has an extraordinary amount of sample code, and this question (as well as many others) could easily be solved by simply visiting Apple's iPhone dev site.
iPhone Dev Site
If you are using a navigation controller, push it onto the navigation controller's stack, as alamodey suggested.
If you want it to be a modal controller (that is, slide up from the bottom and cover the previous controller's view, like the Bookmarks screen in Safari), present it as a modal view controller:
[self presentModalViewController:myNewController animated:YES];
When you want to bring the old controller back, dismiss the modal view controller. From inside the modal view controller:
[self.parentViewController dismissModalViewControllerAnimated:YES];
If you don't want to do either, just remove the current controller's view from the window and add the new controller's:
UIView * containingView = self.view.superview;
[self.view removeFromSuperview];
[containingView addSubview:myNewController.view];
If you go this route, you may want to look into +[UIView beginAnimations:context:], +[UIView setAnimationTransition:onView:], and +[UIView commitAnimations] (if I recall the method names correctly--check the documentation) to animate the transition. You should almost always animate any switch between screens in iPhone OS.
(work in .m class)
#import "classtocall.h"
- (IBAction)ButtonPressed:(id)sender
{
classtocall *mvc = [[classtocall alloc]initWithNibName:#"classtocall" bundle:nil];
[self presentModalViewController:mvc animated:NO];
}
(for window based application)
define in .h class
- (IBAction)ButtonPressed:(id)sender;
where "classtocall" is the class you want to call.
you just need to download sample applications from XCode help. Try Elements and UIcatalog. There are also other - type 'pushViewController' or 'addSubview' adn 'makeKeyAndVisible' in help and download samples
nextscreenViewController *login = [[self storyboard] instantiateViewControllerWithIdentifier:#"nextscreenidentifier"];
nextscreenidentifier.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController: nextscreenidentifier animated: YES];