Answer the question
In order to leave comments, you need to log in
Objective-C. How to call a method from another class?
Hello! I'm just starting to learn Objective C and understand the basics of OOP.
Actually, the question is:
there is a view controller ViewController.
In the interface of the ViewController.h file, the resumeGame and pauseGame methods are declared:
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIView *viewRocket;
@property (weak, nonatomic) IBOutlet UIView *viewBall;
@property (weak, nonatomic) IBOutlet UIView *viewBucket;
@property (weak, nonatomic) IBOutlet UILabel *viewScore;
- (void)resumeGame;
- (void)pauseGame;
@end
- (void)applicationWillResignActive:(UIApplication *)application
{
//Здесь нужен вызов pauseGame
}
Answer the question
In order to leave comments, you need to log in
not everything is so simple and depends on the "architecture". If you used standard templates when creating the project, then you have UINavigationController
available, or the UIViewController itself is available. More precisely, it can only be said if I see the code of the
application:didFinishLaunchingWithOptions method:
In this method, you need to save this UIViewController into a variable that will be declared in the AppDelegate and later call it in these methods.
In general, your task is solved more simply
in the viewDidLoad method of the ViewController class
at the end add
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pauseTheTimer:)
name:UIApplicationWillResignActiveNotification
object:nil];
-(void) pauseTheTimer:(NSNotifycation*)notify{
[self pauseGame];
}
habrahabr.ru/post/103221
In short, then - className methodName and import the required class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question