How do you reload a UIView?
I have a UINavigationController where the user can go back/fourth. When the user goes back, I want that UIView to reload. ( I am actually using an OHGridView ). On my ViewWillDisappear
, I do something like this:
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadOHGridView" object:self];
}
So when they go back, it开发者_运维知识库 will send a NSNotification to the OHGridView to refresh it's data. It get's called, but it get's an error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController reloadData]: unrecognized selector sent to instance 0x4b9e9f0
Here's how I set up my NSNotificationCenter (in my DetailViewController):
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ReloadGridNotification:) name:@"ReloadOHGridView" object:nil];
}
- (void)ReloadGridNotification:(NSNotification *)notification{
[database executeNonQuery:@"DELETE * FROM images"];
[items removeAllObjects];
[self reloadData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Now you would think it would update, but I get that error... Please help!
Coulton
Actually, I wouldn't think that it would update. reloadData
isn't the name of a documented method of UIViewController, and you don't seem to have implemented one yourself. I'm not familiar with OHGridView, but I perhaps that's the object to which you want to send the reloadData message.
So you can change the observer that you set up from self
to your instance of OHGridView, or you can implement a method in your view controller called reloadData
that in turn sends the appropriate reload message to your OHGridView.
精彩评论