UA-17470720-3

Jump to content


Photo
- - - - -

SCArrayOfObjectsSection - Reload data after initial array is empty


  • Please log in to reply
3 replies to this topic

#1 Seth Vanderdrift

Seth Vanderdrift

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 108 posts
Reputation: 20
Excellent

Posted 14 May 2015 - 10:00 AM

Greetings,

 

Getting back into STV, and trying to do things the new IB way (did everything hand setup in STV3)

 

So I have a STV view with an SCArrayOfObjectsSection

 

The array I'm using is loaded from a salesforce query and comes in asynchronously.

 

- On awakeFromNIb, I initialize an empty array for the array of objects (self.dataRows).

- In ObjectsForSection:atIndex:, I return the array (self.dataRows)

 

- In the block that I get the results, add the results to the self.dataRows NSMutableArray as below.

- IF I initialize self.dataRows with no objects:

  self.dataRows = [NSMutableArray arrayWithCapacity:10];

Nothing ever displays.

 

- If I initialize self.dataRows with one object:

NSDictionary *d1 = @{ @"Name" : @"Foo",
                             @"Width" : @50 };

self.dataRows =  [NSMutableArray arrayWithObjects:d1, nil];

The added objects display fine. (If I removeAllObjects for the array and append the new ones, nothing displays.)

 

- I had expected objectsForSection:atIndex to be called whenever reloadBoundValues, but it's only ever called first thing.

 

- (void)request:(SFRestRequest *)request didLoadResponse:(id)jsonResponse {
    NSMutableArray *records = [jsonResponse objectForKey:@"records"];
    NSLog(@"request:didLoadResponse: #records: %lu", (unsigned long)records.count);
    NSMutableArray *results = [NSMutableArray arrayWithArray:records];
    
    // self.dataRows = results;  // DOES NOT DISPLAY ANYTHING 
    
    [self.dataRows addObjectsFromArray:results];

    __weak __typeof__(self) weakSelf = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf.tableViewModel reloadBoundValues];
        [weakSelf.tableViewModel.tableView reloadData];
    });
}

 

Thanks for any insights.  I trying to resist just skipping IB and hand coding...

 

Seth



#2 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 14 May 2015 - 02:27 PM

Greetings Program!

 

I added a refresh action to the DictionaryApp and the following code worked for me but I also experienced the issue where it would not append to an initialized empty array.

 

- (NSMutableArray *)objectsForSection:(SCArrayOfObjectsSection *)objectsSection atIndex:(NSUInteger)index
{
    return self.dataRows; // pass self.objects to the SCArrayOfObjectsSection
}

-(IBAction) refresh:(id)sender
{
    NSMutableArray *results = [@[self.dictionary2] mutableCopy];
//    NSMutableArray *results = [@[self.dictionary2, self.dictionary] mutableCopy];
    
    [self.dataRows removeAllObjects];
    
    [self.dataRows addObjectsFromArray:results];

    __weak __typeof__(self) weakSelf = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf.tableViewModel reloadBoundValues];
        [weakSelf.tableViewModel.tableView reloadData];
    });
}

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 15 May 2015 - 08:01 AM

Hi Seth,

 

This is our bad, "objectsForSection:atIndex:" should be called whenever the section does a reloadBoundValues. We'll fix this in our next release.

 

For the time being, please assign your results array directly to the SCArrayOfObjectsSection as follows:

 

    SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)[self.tableViewModel sectionAtIndex:0];
    SCArrayStore *arrayStore = (SCArrayStore *)objectsSection.dataStore;
    arrayStore.objectsArray = myResults;
    [objectsSection reloadBoundValues];
    [self.tableViewModel.tableView reloadData];

 

Please let me know if this works for you.


Edited by Tarek, 15 May 2015 - 08:03 AM.
Fixed a typo

  • Everett and wizgod like this

#4 Seth Vanderdrift

Seth Vanderdrift

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 108 posts
Reputation: 20
Excellent

Posted 15 May 2015 - 10:56 AM

Tarek, 

 

That worked, thank you.  I thought I was going crazy.  

 

Seth






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users