내가보기 컨트롤러 클래스에서AppDelegate : ViewController에서 값 가져 오기?
- (void)applicationWillTerminate:(UIApplication *)application
에서 변수를 좀하고 싶습니다. 나는 tabbar 응용 프로그램을 빌드하고 appdelegate에만 tabbar 컨트롤러를 추가했습니다.
[window addSubview:tabBarController.view];
은 어떻게 TestViewController에서 변수를 얻을 수 있습니다 : 당신이 요청하지만, 여기에 추측 무엇
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface TestViewController : UIViewController {
IBOutlet UILabel *testLabel;
NSString *currentString; //Value that i want to save at applicationWillTerminate
}
@property (nonatomic, retain) UILabel* testLabel;
@property (nonatomic, retain) NSString* currentString;
@end
고맙습니다.이 작동하지만, currentString 값이 매초마다 변경됩니다. 이게 괜찮습니까? 아니면 매 초마다 currentString을 AppDelegate로 설정하는 것이 좋지 않습니까? – x2on
아마도 이상적이지는 않습니다. UIApplicationDelegate이기 때문에가 아니라 매초 세 개의 메시지를 보내는 것이 비싸기 때문입니다 (sharedApplication, delegate, setCurrentString). TestViewController가 close에서 currentString을 사용하여 수행해야하는 작업을 수행 할 수 있다면 UIApplicationWillTerminateNotification에이를 등록 할 수 있습니다. – dstnbrkr
좋아요. 코드를 다시 작성 했으므로 UIApplicationWillTerminateNotification을 등록하고 거기에서 작업을 수행 할 수 있습니다. 이 힌트를 가져 주셔서 감사합니다! – x2on