Reputation: 3301
How do we find which view is presently first responder when application become active. I know application delegates applicationWillEnterForeground and applicationDidBecomeActive will be called in cases, how can I use this to intimate view which is first responder.
I have googled and stack overflowed didn't find exact answer. Any idea friends..
Upvotes: 2
Views: 4513
Reputation: 38239
Getting reference to the top-most view/window in iOS application
topMostView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];
Refer getting-reference-to-the-top-most-view-window-in-ios-application link.
EDIT intiate action to current view to perform when application returing from background
Add BOOL applicationFromBackground; make its property in appDelegate.
Intially it will be applicationFromBackground = FALSE; in application didFinishLaunchingWithOptions method;
Now application enters foreground :
- (void)applicationDidEnterBackground:(UIApplication *)application
{
applicationFromBackground = TRUE;
}
Now in all view controllers's view will appear method which will be called for topmost viewcontroller so do this:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Create AppDelegate instance
AppDelegate *objAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if(objAppDelegate.applicationFromBackground)
{
applicationFromBackground = FALSE;
//do what u want.
}
}
Upvotes: 4