UA-17470720-3

Jump to content


Photo
- - - - -

Reloading section after modifying items array

sections general cells

  • Please log in to reply
No replies to this topic

#1 Garrison

Garrison

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 11 posts
Reputation: 4
Good

Posted 29 September 2014 - 08:56 AM

I have a section being created that is populated from the objects in an NSMutableArray called _searchResults.  When the section is initially created, _searchResults is empty, but after doing an async call I populate the _searchResults array and need to reload the section with the new data.  I can't figure out why my section doesn't get refreshed...I feel like it's because the tableViewModel doesn't know that the number of items has changed, but I'm not entirely sure.  Can anyone provide some guidance?  The only thing I've been able to do that works so far is removingAllSections and then rebuilding my table, but that seems like a totally wrong solution to me...

 

The relevant code is below:

@property (nonatomic, strong) NSMutableArray *searchResults;

Then in viewDidLoad

SCClassDefinition *definition = [SCClassDefinition definitionWithClass:[SearchResult class] autoGeneratePropertyDefinitions:YES];
    
SCArrayOfObjectsSection *searchSection = [[SCArrayOfObjectsSection alloc] initWithHeaderTitle:@"Search Results" items:_searchResults itemsDefinition:definition];
    
[self.tableViewModel addSection:searchSection];

Then when the UISearchBar Search button is tapped:

 

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    __weak typeof(self) weakSelf = self;
    [[ApiClient sharedClient] search:searchBar.text successBlock:^(NSDictionary *responseObject) {
        
        _searchResults = [responseObject objectForKey:@"results"];
               
        [weakSelf.tableViewModel reloadBoundValues];
        [weakSelf.tableViewModel.tableView reloadData];
        
        [searchBar resignFirstResponder];
        
    } failureBlock:^(NSDictionary *responseObject) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"There was an error searching. Please try again" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        
        [alert show];
        
    }];
}

 

 







Also tagged with one or more of these keywords: sections, general, cells

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users