applicationWillEnterForeground: récupérer les Données à partir de ViewController
Je veux que mon application pour récupérer les données dès que l'application des commutateurs de l'arrière-plan au premier plan.
C'est mon code:
DataAppDelegate.h
#import <UIKit/UIKit.h>
#import "DataViewController.h"
@class DataViewController;
@interface DataAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
DataViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet DataViewController *viewController;
@end
AppDelegate.m
#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];
}
DataViewController.h
@interface DataViewController : UIViewController<UIWebViewDelegate, ADBannerViewDelegate> {
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
DataViewController.m
- (void) viewDidLoad {
[self loadData];
}
- (void)loadData {
//contains information the ViewController makes use of
}
-(IBAction)refresh:(id) sender {
[self loadData];
}
Avec ce code j'obtiens deux mises en garde:
'DataViewController" ne peut pas répondre à "+actualiser"
mais il fonctionne.
Si je coupe la ligne dans la méthode "applicationDidEnterBackground:" il ne fonctionne plus, l'application se bloque.
Pourquoi?
Comment dois-je remplir le applicationDidEnterBackground: méthode?
Ai-je besoin de réserver de l'espace pour mon application? comment dois-je faire?
Comment suis-je en mesure de résoudre ces avertissements?
Appearently mon application ne connais pas la méthode refresh, mais pourquoi faut-il travailler dans mon exemple ci-dessus?
Merci d'avance pour votre aide 🙂
OriginalL'auteur Dwain | 2011-02-07
Vous devez vous connecter pour publier un commentaire.
Changement
à
Désolé, mise à jour de ma réponse.
d'accord, semble fonctionner maintenant, pas de mises en garde plus et l'application cesse de s'écraser, je vous remercie beaucoup. Je dois attendre le prochain données recharger, mais je pense que cela devrait fonctionner maintenant.
hum eh bien, - (void) viewDidLoad { [auto loadData]; je reçois le même message d'avertissement dans ce code 😡
Lieu - (void)loadData méthode ci-dessus, l' - (void)viewDidLoad méthode, de sorte que le compilateur sait que la fonction existe.
OriginalL'auteur JustSid