Ios 在一个选项卡中加载数据,在另一个选项卡中查看数据,但该表获胜';t重新加载
我有一个选项卡控制器,其中有4个选项卡。在第二个选项卡中,我输入数据并将数据保存到plist。在第四个选项卡中,我将读回plist,生成一个字典项(公司名称)的数组,并将它们显示在表中。我在viewDidLoad方法中执行此操作 这对于现有数据很有效。但是,当我在第二个选项卡中添加数据,然后转到第四个选项卡时,我无法弄清楚如何让表重新加载数据……我在viewDidAppear方法中尝试了[table reloadData],没有成功。还试图用一个按钮重新加载数据,但什么也没有 有人能给我指出正确的方向吗 下面是一些代码: AppDelegate:Ios 在一个选项卡中加载数据,在另一个选项卡中查看数据,但该表获胜';t重新加载,ios,cocoa-touch,reload,Ios,Cocoa Touch,Reload,我有一个选项卡控制器,其中有4个选项卡。在第二个选项卡中,我输入数据并将数据保存到plist。在第四个选项卡中,我将读回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;
}
在我的第四个ViewController.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;
}
需要发布更多的代码,以确保,但我想说,你不是每次初始化第四个标签。意思是你的代码是这样的 初始化{ [tab4 init] } 呼叫视图{ [推视图选项卡4] } 你好像在哪里 初始化{ } 呼叫视图{ [tab4 init] [推视图选项卡4] } (意思是在你准备使用它之前不要初始化4tab)
它应该查询plist fresh,之前没有任何查询结果嘿,谢谢你的回复。我有点明白你的意思,也有点不明白你的意思,我在上面发布了一些代码来展示我是如何添加选项卡视图控制器并将数据放入表中的。