在一个选项卡中加载数据,查看另一个选项卡但不会重新加载表

时间:2012-05-15 17:33:00

标签: ios cocoa-touch reload

我有一个标签控制器,里面有4个标签。在第二个选项卡中,我输入数据并将该数据保存到plist。在第四个选项卡中,我正在阅读plist,创建一个字典项(公司名称)的数组并将其显示在表中。我在viewDidLoad方法中这样做。

这适用于现有数据。但是,当我在第二个选项卡中添加数据然后转到第四个选项卡时,我无法弄清楚如何让表重新加载数据...我在viewDidAppear方法中尝试了[table reloadData],没有运气。还尝试了一个按钮来重新加载数据,但没有。

有人能指出我正确的方向吗?

以下是一些代码:

AppDelegate:

- (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;

}

1 个答案:

答案 0 :(得分:0)

需要发布更多代码才能确定,但​​我会说你不是每次都初始化第4个标签。这意味着您的代码是这样的。

初​​始化{ [tab4 init] }

callview { [pushView tab4] }

就像你做的那样

初​​始化{ }

callview { [tab4 init] [pushView tab4] }

(意思是在你打算使用之前不要初始化4tab)

它应该查询plist新鲜,没有任何先前的查询结果