【发布时间】:2014-01-25 17:09:35
【问题描述】:
在我的 ViewController.m 中,我有无效的“保存数据”:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize myDatePicker, myTextField;
-(void)saveData
{
NSArray *value = [[NSArray alloc] initWithObjects:[myTextField text],[myDatePicker date], nil];
[value writeToFile:[self getFilePath] atomically:YES];
}
我想在我的 AppDelegate.m 中使用我的无效“保存数据”:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.ViewController saveData];
}
但 Xcode 无法识别“ViewController”和“saveData”。
我不知道我是否必须在我的 AppDelegate 中#import 一些东西,请帮忙。
【问题讨论】:
-
当前答案是正确的 - 让您的视图控制器观察您要处理的通知。但是你的电话是非常规的。您是否有一个属性来引用您尝试调用其方法的视图控制器。编译器错误告诉您它们没有正确设置。
标签: objective-c viewcontroller appdelegate