【发布时间】:2012-01-29 06:10:34
【问题描述】:
我有一个页面,用于检查捆绑包中是否有员工列表,如果有,则将它们显示在表格视图中。但是如果捆绑包上没有列表,它会抛出一个模态视图控制器。然后需要有人登录,登录经过身份验证,然后下载数据。
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];
}
一旦我得到列表,我将其归档,然后将其读回。如果列表中有信息,我将调用委托方法。
更新
这里是委托方法
- (void)passUserInfo: (NSMutableArray *)employeeDataArray
{
employeeData = [[NSMutableArray alloc] initWithArray:employeeDataArray];
[self.tableView reloadData];
/////FIX////////
[createIndexedArray];
}
一旦被调用,什么都不会发生。我尝试关闭有效的模态视图,但是第一页没有刷新,我的应用程序被遗忘了。我只是对它的进展以及如何刷新第一页上的表格视图感到困惑。
有没有我遗漏的步骤?我已经尝试跟踪它并在此步骤之后将其丢失。
【问题讨论】:
-
粘贴模式视图关闭时调用的方法。
-
@h2c03 我刚刚添加了委托方法
-
您已经注释掉了 [self.tableView reloadData] - 取消注释它可能会很有用 ;)
-
现在评论的,那是来自测试的
-
我用丢失的代码更新了我的方法,并在下面解释了我的答案。
标签: ios4 uitableview modalviewcontroller