If I get an alert in my application and if I put application in background and press application icon to enter the application, a splash screen is displayed and then the alert pop up. Why splash screen appears?
And if alert is not present and I put application in background and press application icon to enter the application, splash screen is not displayed.
First you have to make the UIAlertView a property in your class.
In your AppDelegate Class you can implement the applicationDidEnterBackground: Method in wich you can put something like this:
[yourViewController.yourAlert dismissWithClickedButtonIndex:0 animated:NO];
This should dismiss the alert if your app enters the background.
Hope this helps!
The splash screen is as #akshay1188 mentions, is the Default.png in your project file. The reason for it being displayed, based on my best assumption, is because the OS has not managed to take a screenshot of your App before you go back to it. See this answer to a StackOverflow question where it was discussed.
As for the UIAlertView, #pKoul's anwser got my upvote.
Maybe you can use the notification posted UIApplicationDidEnterBackgroundNotification in any class that needs some cleanup before entering bg. Do not forget to remove the observer in dealloc.
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(cleanup:)
name: UIApplicationDidEnterBackgroundNotification
object: nil]
The splash screen is actually the launch image that you might be using as Default.png
If you want to dismiss all AlertViews programmatically you have to Remember a Reference to the currently shown Alterviews. I recommend a Singleton class where you ask for an AlertView and wich saves a Reference to the AlertView.
then you could use the
`- (void)applicationDidEnterBackground:(UIApplication *)application`
in your AppDelegate and call a Function on the Singleton Class, wich itself calls
[alert dismissWithClickedButtonIndex:0 animated:YES];
at all Alertviews.
Related
I want Button action done automatically when a view load. Is it possible?
The other answers are correct in that setting the action that your button is tied to, then in your viewDidLoad:, call that function will work. I will just chime in with another method for others info.
You can send it a control event telling it that the button should act as if it has been pressed:
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
This is useful when you do not have an outlet to the button. For instance, I created an app where the user can press on a web view and launch a youtube video. It was also required that if the user presses a "video" button, then the same youtube video would launch. Basically, I had to fire a press event on the web view. So i searched through its views and found the button, from there I called the above line, and the webview pushes a video view controller for the youtube video.
Certainly Yes. Call your method as
assuming your method declaration as
-(IBAction)yourButtonTapEvent:(id)sender;
[self yourButtonTapEvent:nil];
Yes, in your viewDidAppear method, just call the action you are providing for that specific button.
- (void)viewDidAppear:(BOOL)animated
{
[self yourButtonAction:nil];
[super viewDidAppear:animated];
}
I have a button ON/OFF in my viewcontroller that plays some music when it is turned on by the user. Now if the user clicks the iPhone home button and re-launches my app again, the button is shown as "ON" but there is no music playing. So the user has to hit ON-OFF-ON again for music to start playing again.
Anyone know how can I call my ON/OFF view controller button so that I can set it to OFF when app enters background and set it to ON and play the music when it enters forground in these app delegates?
I know I need to write to a plist file the button & music state on applicationDidEnterBackground. I don't know how can I get to those action from appdelegate since they are defined in my viewcontroller.
Similary, when the app enters the foreground I will read the saved plist file and then set the state of music and button again. Again, I don’t know how to call my controller methods from delegate.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(#"Inside applicationDidEnterBackground");
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"Inside applicationWillEnterForeground");
}
One possible methodology is to send a message from the app delegate to the view controllers to save or restore state. Then the view controller, which have access to their internal state, can implement any needed save and restore methods.
If the app delegate does not directly contain a reference to the active view controller, it can send the message down the chain, to root view controller, which can then send a message to the next view controller, and etc., each controller saving anything it considers important on the way down.
All you need to do is subscribe to the UIApplicationDidEnterBackgroundNotification notification in your view controller
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(handleEnteredBackground:)
name: UIApplicationDidEnterBackgroundNotification
object: nil];
Theres also a notification for DidEnterForeground too.
My app downloads data from internet when it starts, during the splash screen.
It does the same when, from the background, it enters in foreground (when the user open the app from the background).
When the app is open, the user can push some views in order to read the informations downloaded.
I want that when the app is open from the background state, the viewControllers are popped until the first view is showed...
I want to do something like this in my AppDelegate:
while ([self.view isNotMainView]) //of course this method doesn't exists
{ [self.navigationController popViewControllerAnimated:NO]; }
is it possible?
Thanks
Just use:
[self.navigationController popToRootViewControllerAnimated:NO];
Hope that Helps!
hope Following link will help...
How are people popping their UINavigationController stacks under a UITabBarController?
You can keep a reference or Current navigation controller in your appdelegate OR you can write this in you viewDidUnload OR viewWillDisapper for popping navigation to root when application goes to background.
You could just compare the view against your main view if you have a reference hanging around:
while (self.view != myMainView)
etc. (Assuming that self.view is the correct reference as well.)
I work on a project on iPhone iOS 4 with Xcode 4.
I have a view with a UIButton. The title of the UIButton is set in viewDidLoad. So when app starts, the Button has a title.
However, my app has a Settings bundle and the button title can be also changed in Settings app. So I clic on the home button, my app quits, I go to the Settings app, and set a new button title.
When I quit Settings and restart my app, the button title is not refreshed, it is the old button title. Everything is as I had left.
Only if I turn off the iPhone, then turn on and relaunch my app (i.e. at full restart) the button has at the new title.
How to make sure that the button title changes when the app is (not full) restarted?
Thank you.
You want to update the settings in applicationDidEnterForeground. That gets called when it resumes.
Edit: Had a typo, it should be
- (void)applicationWillEnterForeground:(UIApplication *)application
see docs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
I was mistaken in thinking that the viewWillAppear message would be sent to the ViewController when the app became active again after switching back from the Settings app. There is a notification posted when the app becomes active, however, so you should be able to accomplish what you want by registering your ViewController to receive UIApplicationDidBecomeActiveNotification notifications:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(refreshButtonTitle:) name:UIApplicationDidBecomeActiveNotification object:nil];
and then create the appropriate method in your ViewController to be called when the notification is fired:
- (void)refreshButtonTitle:(NSNotification *)notification {
// update the title of your button here
}
You can register to receive NSUserDefaultsDidChangeNotifications and then act accordingly to update your UI.
I have an iPhone application that I use the ABPersonViewController and I allow delete.
The thing is that the application is a TabBar application and when i use the regular delete method I get this warning:
Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].
the problem is that when I try to press on the "Cancel" of the delete, it does not work!
I want the action sheet to pop up from the TabBar, How do I do that?
this is the code:
if ([personController respondsToSelector:#selector(setAllowsDeletion:)])
[personController setAllowsDeletion:YES]; //CAN CAUSE THE APPLICATION TO BE DENIED FROM THE APP-STORE
To display an action sheet from a tab bar, you can call the following within the view controller that is presenting it: [actionSheet showFromTabBar:self.tabBarController.tabBar];
This answer is explained in this post.