【问题标题】:Loading data in one tab, viewing it another but the table won't reload在一个选项卡中加载数据,在另一个选项卡中查看它,但表格不会重新加载
【发布时间】:2012-05-23 06:29:14
【问题描述】:

我有一个标签控制器,里面有 4 个标签。在第二个选项卡中,我正在输入数据并将该数据保存到 plist。在第 4 个选项卡中,我正在阅读 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;

}

【问题讨论】:

    标签: ios cocoa-touch reload


    【解决方案1】:

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

    初始化{ [tab4 初始化] }

    通话视图{ [pushView tab4] }

    好像你在哪里

    初始化{ }

    通话视图{ [tab4 初始化] [pushView tab4] }

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

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

    【讨论】:

    • 您好,谢谢您的回复。我有点明白你在说什么,我在上面发布了一些代码来展示我如何添加选项卡视图控制器并将数据放入表中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    相关资源
    最近更新 更多