模态视图关闭后 TableView 未重新加载

发布于 2024-12-29 17:49:31 字数 2444 浏览 0 评论 0原文

我有一个页面,用于检查捆绑包中是否有员工列表,如果有,则将其显示在表格视图中。但是,如果包中没有列表,它会抛出一个模式视图控制器。然后需要有人登录,登录经过身份验证,然后下载数据。

ModalView 设置为第一页的委托。我可以很好地调用委托方法并传递列表,但是当 ModalView 被关闭时,表不会使用数据重新加载表视图。如果我再次运行该项目,它会立即将列表加载到表视图中。

这是第一页的 ViewDidLoad 上的方法

[self checkLastLoginDate];
[self loadDataIntoArray];


if (currentData && dataLoadedIntoArray) {
    NSLog(@"sweet the data is current");
    [self createIndexedArray];
}    
else{
    NSLog(@"Data not loaded and not current");
    //push login view


///if ipad do this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{
    //the above code was working fine. I am just testing pushing a dynamic xib
    LoginViewControlleriPad *loginControlleriPad = [[LoginViewControlleriPad alloc] initWithNibName:@"LoginViewControlleripad" bundle:nil]; 
    loginControlleriPad.modalPresentationStyle = UIModalPresentationFormSheet;
    loginControlleriPad.delegate = self;

    [self presentModalViewController:loginControlleriPad animated:YES];
    [self createIndexedArray];
    [loginControlleriPad dismissModalViewControllerAnimated:NO];               
    [self.tableView reloadData];
}

前两个方法检查以确保捆绑包中存在数据并且上次登录日期在 15 天内。

如果是,那么我创建一个 IndexedArray 并且它显示得很好。

如果数据不在捆绑包中或日期过旧,我会检查设备并使用模式视图。委托已设置并且 ModalView 出现。

在 ModalView 中,我使用同步和异步请求来访问服务器以获取所需信息。然后我创建列表并将其传回第一页。

连接建立后,我们在列表上做一些工作,然后将其保存到捆绑包中。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:kEMPLOYEE_PLIST];

/////write to file/////
[cleanResults writeToFile:path atomically:YES];

employeeList = [[NSMutableArray alloc ]initWithContentsOfFile:path];

if (employeeList != nil) 
{   
    [delegate passUserInfo:employeeList];

    //cant get login view to dismiss
    //[self dismissModalViewControllerAnimated:YES];
}

获得列表后,我会将其保存到文件中,然后将其读回。如果列表中有信息,我将调用委托方法。

更新

这是 delgate 方法,

- (void)passUserInfo: (NSMutableArray *)employeeDataArray
{
    employeeData = [[NSMutableArray alloc] initWithArray:employeeDataArray];
    [self.tableView reloadData];

    /////FIX////////
    [createIndexedArray];
}

一旦被调用,什么也不会发生。我尝试关闭模态视图,该视图有效,但随后第一页不刷新,我的应用程序迷失在遗忘中。我只是对它的进展以及如何刷新第一页上的表格视图感到困惑。

我缺少一个步骤吗?我尝试过跟踪它并在这一步后丢失它。

I have a page that checks if there is a list of employees on the bundle, and if there is it displays them in a table view. But if there is no list on the bundle it throws up a modal view controller. That then requires someone to login, the login is authenticated and then data is downloaded.

The ModalView is setup to be a delegate of the first page. I can call the delegate method just fine and pass the list, but when the ModalView is dismissed the table does not reload the tableview with the data. If i run the project again it loads the list up in the table view instantly.

Here is the method on the ViewDidLoad of the first page

[self checkLastLoginDate];
[self loadDataIntoArray];


if (currentData && dataLoadedIntoArray) {
    NSLog(@"sweet the data is current");
    [self createIndexedArray];
}    
else{
    NSLog(@"Data not loaded and not current");
    //push login view


///if ipad do this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{
    //the above code was working fine. I am just testing pushing a dynamic xib
    LoginViewControlleriPad *loginControlleriPad = [[LoginViewControlleriPad alloc] initWithNibName:@"LoginViewControlleripad" bundle:nil]; 
    loginControlleriPad.modalPresentationStyle = UIModalPresentationFormSheet;
    loginControlleriPad.delegate = self;

    [self presentModalViewController:loginControlleriPad animated:YES];
    [self createIndexedArray];
    [loginControlleriPad dismissModalViewControllerAnimated:NO];               
    [self.tableView reloadData];
}

The first two methods check to make sure the data exists on the bundle and that the last login date is within 15 days.

if it is then I create an IndexedArray and it displays nicely.

If the data is not on the bundle or the date is to old I check the device and use a modal view. The delegates are set and the ModalView Appears.

In the ModalView I use a syncronus and asyncronus request to hit a server for the required information. Then I create the list and pass it back to the first page.

Once the connection is made and we do a little work on the list we save it to the bundle.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:kEMPLOYEE_PLIST];

/////write to file/////
[cleanResults writeToFile:path atomically:YES];

employeeList = [[NSMutableArray alloc ]initWithContentsOfFile:path];

if (employeeList != nil) 
{   
    [delegate passUserInfo:employeeList];

    //cant get login view to dismiss
    //[self dismissModalViewControllerAnimated:YES];
}

Once I get the list I right it to file and then read it back in. If there is info in the list I call the delegate method.

UPDATE

Here is the delgate method

- (void)passUserInfo: (NSMutableArray *)employeeDataArray
{
    employeeData = [[NSMutableArray alloc] initWithArray:employeeDataArray];
    [self.tableView reloadData];

    /////FIX////////
    [createIndexedArray];
}

Once that is called nothing happens. I tried dismissing the modal view, which works, but then the first page does not refresh and my app gets lost in the oblivion. I am just confused at were it is going and how i can refresh the tableview on the first page.

Is there a step I are missing? I have tried tracking it and lose it after this step.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2025-01-05 17:49:31

我实际上发现我的代码设置正确,我只需要调用一个将数组排序为字母数组的方法。一旦我从委托方法调用该方法,它就像蛇符一样工作。

更新

我有一个创建索引数组的方法。当我在委托方法中调用它时,它重新加载页面并将新内容插入表视图中。我很确定它一直在重新加载,我只是没有调用填充表视图中显示的数组的方法。

I actually figured out that my code was setup right, i just needed to call a method that sorted the array into an alphabetic array. Once i called that method from the delegate method it worked like a snake charm.

UPDATE

I had a method that created an indexed array. When i called that inside the delegate method it reloaded the page and inserted the new into the table view. I am pretty sure it was reloading the whole time, i was just not calling the method that was populating the array that was being being displayed in the tableview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文