Note that there are some explanatory texts on larger screens.

plurals
  1. POapplicationWillEnterForeground: reload Data from ViewController
    primarykey
    data
    text
    <p>I want my app to reload data as soon as the app switches from the background to the foreground.</p> <p>Thats my code:</p> <p>DataAppDelegate.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "DataViewController.h" @class DataViewController; @interface DataAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { UIWindow *window; DataViewController *viewController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet DataViewController *viewController; @end </code></pre> <p>AppDelegate.m</p> <pre><code>#import "DataAppDelegate.h" #import "DataViewController.h" @implementation DataAppDelegate @synthesize window; @synthesize viewController; #pragma mark - #pragma mark Application lifecycle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the view controller's view to the window and display. [self.window addSubview:viewController.view]; [self.window makeKeyAndVisible]; return YES; } - (void)applicationWillResignActive:(UIApplication *)application { NSLog(@"app will resign active"); } - (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"app did enter background"); [DataViewController refresh]; } - (void)applicationWillEnterForeground:(UIApplication *)application { NSLog(@"app will enter foreground"); [DataViewController refresh]; } </code></pre> <p>DataViewController.h</p> <pre><code> @interface DataViewController : UIViewController&lt;UIWebViewDelegate, ADBannerViewDelegate&gt; { IBOutlet UIWebView *webView; IBOutlet UITextField *addressBar; IBOutlet UIActivityIndicatorView *activityIndicator; IBOutlet UILabel *myField2; IBOutlet UILabel *myField3; IBOutlet UILabel *myField4; IBOutlet UILabel *myField5; IBOutlet UILabel *myField6; ADBannerView *adView; BOOL bannerIsVisible; } @property(nonatomic,retain) UIWebView *webView; @property(nonatomic,retain) UITextField *addressBar; @property(nonatomic,retain) UIActivityIndicatorView *activityIndicator; @property(nonatomic,assign) BOOL bannerIsVisible; -(IBAction) goBack:(id)sender; -(IBAction) goForward:(id)sender; -(IBAction) refresh:(id)sender; -(IBAction) goImpressum:(id)sender; @end </code></pre> <p>DataViewController.m</p> <pre><code>- (void) viewDidLoad { [self loadData]; } - (void)loadData { // contains information the ViewController makes use of } -(IBAction)refresh:(id) sender { [self loadData]; } </code></pre> <p>With that code i get two warnings:</p> <p>'DataViewController' may not respond to '+refresh'</p> <p>but it does work.</p> <p>If i cut the line in method "applicationDidEnterBackground:" it doesn't work anymore, the app crashes. Why? How do i have to fill the applicationDidEnterBackground: method? DO i need to book some space for my application? how do I do that?</p> <p>How am I able to solve these warnings? Appearently my application does not know the refresh method, but why does it work in my example above?</p> <p>Thanks in advance for your help :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload