我有一个标签控制器,里面有 4 个标签。在第二个选项卡中,我正在输入数据并将该数据保存到 plist。在第 4 个选项卡中,我正在阅读 plist,将其中一个字典项(公司名称)制作成一个数组并将它们显示在表格中。我在 viewDidLoad 方法中这样做。
这适用于现有数据。但是,当我在第二个选项卡中添加数据然后转到第四个选项卡时,我无法弄清楚如何让表重新加载数据......我在 viewDidAppear 方法中尝试过 [table reloadData],没有运气. 还试图有一个按钮来重新加载数据,但没有。
有人可以指出我正确的方向吗?
这是一些代码:
应用委托:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//We need to implement the view controllers within the tab controller and make the tab controller the root controller of our app - note we are only using view 1-4 at first.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
ThirdViewController *thirdView = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
FourthViewController *fourthView = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, thirdView, fourthView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
self.window.rootViewController = self.tabController;
//end custom code
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
在我的 FourthViewController.h 中:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//add our own image to the tab bar
self.title = @"Results";
self.tabBarItem.image = [UIImage imageNamed:@"btnResults.png"];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
newFileManager = [FileManager new];
NSMutableDictionary* surveyResults = [newFileManager readPlist];
NSMutableArray* tempArray = [[NSMutableArray alloc] init];
for(NSString* thisCompanyName in surveyResults) {
[tempArray addObject:thisCompanyName];
}
companyNames = [[NSArray alloc] initWithArray:tempArray];
NSArray* sortedCompanyNames = [companyNames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
self.companyNamesTable = sortedCompanyNames;
}