Welcome, Guest
Username Password: Remember me

Refreshing table data not working for me
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Refreshing table data not working for me

Refreshing table data not working for me 1 year, 5 months ago #1

Hi,

I may be doing something wrong here, but I've created a table with the following code. The problem is that when I come back to this screen, my data is not updated in the table. I'm rolling my own detail views because my selection tables can be complex and are generated using asynchronous web services calls. A couple of my selection screens are hierarchical in nature. Another provides a search field also. So that's why I'm rolling my own. The problem is, when I select a value and come back to my first view, the selections in my table aren't refreshing. I'm even calling [self.aTableView reloadData] on my table class, but it's still not updating.

Here's how I'm generating my table. Maybe I'm doing something wrong?
 
SCTableViewModel *model = [[SCTableViewModel alloc] initWithTableView:self.aTableView withViewController:self];
SCTableViewSection *section = [[SCTableViewSection alloc] initWithHeaderTitle:nil];
 
SCTextFieldCell *cell = [[SCTextFieldCell alloc] initWithText:NSLocalizedString(@"Keyword", @"") withPlaceholder:NSLocalizedString(@"enter keyword", @"") withBoundObject:self.filter withTextFieldTextPropertyName:@"searchTerm"];
cell.commitChangesLive = YES;
cell.textField.textAlignment = UITextAlignmentRight;
cell.textField.clearButtonMode = UITextFieldViewModeAlways;
[section addCell:cell];
[cell release];
 
// cell = [[SCLabelCell alloc] initWithText:NSLocalizedString(@"Category", @"") withBoundKey:@"category" withLabelTextValue:self.filter.category.name];
 
cell = [[SCLabelCell alloc] initWithText:NSLocalizedString(@"Category", @"") withBoundKey:@"category" withLabelTextValue:self.filter.selectedCategory.name];
 
cell.selectable = YES;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
[section addCell:cell];
[cell release];
 
cell = [[SCLabelCell alloc] initWithText:NSLocalizedString(@"Manufacturer", @"") withBoundKey:@"manufacturer" withLabelTextValue:self.filter.manufacturer.name];
cell.selectable = YES;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
[section addCell:cell];
[cell release];
 
cell = [[SCLabelCell alloc] initWithText:NSLocalizedString(@"Price Range", @"") withBoundKey:@"priceRange" withLabelTextValue:self.filter.priceRange.rangeDisplay];
cell.selectable = YES;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
 
 
[section addCell:cell];
[cell release];
 
 
[model addSection:section];
[section release];
 
self.tableModel = model;
[model release];
 
 


I also implemented didSelectRowAtIndexPath as follows:
 
-(void) tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SCTableViewCell *cell = [tableViewModel cellAtIndexPath:indexPath];
 
if ([cell.boundKey isEqualToString:@"category"]) {
CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:@"CategoryView" bundle:nil];
viewController.filter = self.filter;
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
} else if ([cell.boundKey isEqualToString:@"manufacturer"]) {
BrandSearchViewController *viewController = [[BrandSearchViewController alloc] initWithNibName:@"BrandSearchView" bundle:nil];
viewController.filter = self.filter;
viewController.isSelectionController = YES;
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
} else if ([cell.boundKey isEqualToString:@"priceRange"]) {
PriceRangeViewController *viewController = [[PriceRangeViewController alloc] initWithNibName:@"PriceRangeView" bundle:nil];
viewController.filter = self.filter;
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
}
 



If there's any better way to do this, please let me know.

Thanks!

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Refreshing table data not working for me 1 year, 5 months ago #2

As a follow-up to this post, I'll further explain that I'm passing in an STIFilter object from my main FilterViewController to my other view controllers. The other view controllers update the selected values in the STIFilter class. When I come back to my FilterViewController, I want the selections to be updated on that screen.

Thanks again,

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Refreshing table data not working for me 1 year, 5 months ago #3

Hi Brendan,

Thanks for the follow up part, I was just going to ask you if the data is changed externally in the detail views. Whenever the data changes by means that are outside of STV's control, you should call [self.tableModel reloadBoundValues] to have these changes reflected back in STV. Please tell me if this solves the problem for you.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Refreshing table data not working for me 1 year, 5 months ago #4

Hello Tarek,

Thanks for your response. Unfortunately that doesn't help. In fact, I found that method yesterday and though "hmm... I wonder if this will refresh the data?". Well, it didn't. I have the following code in viewWillAppear:
 
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableModel reloadBoundValues];
[self.aTableView reloadData];
}
 


I tried putting it into viewDidAppear too, but that also didn't make a difference.

If I use gdb to print out the value of my selected category (which is a property of my STIFilter class), it shows the correctly selected category. But the table still doesn't get updated with the value.

The selected category is bound as follows:
 
cell = [[SCLabelCell alloc] initWithText:NSLocalizedString(@"Category", @"") withBoundKey:@"category" withLabelTextValue:self.filter.selectedCategory.name];
 


I have the same issue with the rest of my cells (manufacturer and price range).

Also note, I added an SCSelectionCell to let a user pick their sort order for the search results. This updates properly when they select a sort order. But in this situation I'm letting STV do all the work.

Thanks,

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Refreshing table data not working for me 1 year, 5 months ago #5

How are you changing the values Brendan? Key-bound cells read their values from the tableModel.modelKeyValues dictionary. Are you sure you save your changes there using the same key the cell is bound to?
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
Last Edit: 1 year, 5 months ago by tarekskr.

Re: Refreshing table data not working for me 1 year, 5 months ago #6

As another followup, looking into my tableModel, the modelKeyValues still shows "Electronics" as the selected category even though I've now selected "Home Video":

0 : <CFString 0x21100c [0x3ea4f9fc]>{contents = "sortBy"} = <CFNumber 0x429790 [0x3ea4f9fc]>{value = +1, type = kCFNumberSInt32Type}
2 : <CFString 0x20a77c [0x3ea4f9fc]>{contents = "category"} = <CFString 0x4e8390 [0x3ea4f9fc]>{contents = "Electronics"}



po [[self filter] selectedCategory] name]
Home Video
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com
  • Page:
  • 1
  • 2
Time to create page: 1.25 seconds