0
我有一個帶有4個選項卡的選項卡控制器。在第二個選項卡中,我輸入數據並將數據保存到plist。在第四個選項卡中,我正在閱讀plist,製作一個字典項目(公司名稱)的數組並將其顯示在表格中。我在viewDidLoad方法中這樣做。將數據加載到一個選項卡中,查看它但是不會重新加載
這適用於現有數據。然而,當我在第二個選項卡中添加數據,然後轉到第4個選項卡時,我無法弄清楚如何讓表重新加載數據......我在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;
}
嘿
應該查詢的plist新鮮,沒有任何事先的查詢結果,感謝您的答覆。我有點不明白你在說什麼,我在上面發佈了一些代碼,以顯示我如何添加選項卡視圖控制器和獲取數據到表中。 – PruitIgoe