开发者

Problem with ViewDidLoad method

I开发者_开发百科 have a problem with the methoed ViewDidLoad... At the start, my application must run some code but if I load one other viewController and than I return in the main Controller the application runs again the code! I want that my app runs this code at the start but when the user returns to the main view the app does anythings!


You could put the code you need executed in the Application Delegate and just run it at startup from there.

In your project, you should have a pair of files and they should both be name like this: yourprojectnameAppDelegate, go into the implementation one.

Then just put your code in the following method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    //your code here

    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[Hungry_ZombiesViewController alloc] initWithNibName:@"Hungry_ZombiesViewController" bundle:nil]; 
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜