zach
zach

Reputation: 1361

TableView not reloading after modalview dismissed

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.

Upvotes: 0

Views: 619

Answers (1)

zach
zach

Reputation: 1361

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.

Upvotes: 1

Related Questions