How to reload data in a table view?

465 views
Skip to first unread message

Nielson Rolim

unread,
Feb 4, 2011, 1:41:38 PM2/4/11
to ObjectiveResource
I did a very simple iPhone app using ObjectiveResource. It access my
Rails webservice, reads all the products of the Model Tbprod and shows
them in a TableView:

- (void)viewDidLoad {
[super viewDidLoad];

NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithArray:
[Tbprod findAllRemote]];
self.produtos = tmpArray;
[tmpArray release];
}

Until here, everything is working fine. But when I change a register
in my table through my Rails app and restart my iPhone app, it doesn't
update the data. It still shows the old data instead.

I tried this:

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView reloadData];
}

But it didn't work.

Does anybody have any glue?

Bruno Fuster

unread,
Feb 4, 2011, 1:49:03 PM2/4/11
to objectiv...@googlegroups.com
maybe you should retain or copy tmpArray 

although I think you should use just your mutable self.produtos array... 

override init

- initWithStyle... {
    self.produtos = [[NSMutableArray alloc] init];
}

add values when viewDidLoad:
[self.produtos addEntriesFromDictionary:[Tbprod findAllRemote]];

and reload your table:
[[self tableView] reloadData]; instead of [[self.tableView] reloadData];

PS: you shouldn't call [Tbprod findAllRemote] the way you're doing! your app will freeze... you need to create async calls using NSOperationQueues, so that code should be more complex than that using delegates


--
You received this message because you are subscribed to the Google Groups "ObjectiveResource" group.
To post to this group, send email to objectiv...@googlegroups.com.
To unsubscribe from this group, send email to objectiveresou...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/objectiveresource?hl=en.




--
Bruno Fuster

Reply all
Reply to author
Forward
0 new messages