Reputation:
I have a view that is used to update some NSUserDefaults. These defaults have an impact on a table in a different view. The issue I'm facing is that I want to reload the data in the table before the view is displayed again.
At present I have viewA
which contains the table, I then display viewB
using the following code:
[self presentModalViewController:viewB animated:YES];
Once the user has updated the NSUserDefaults viewB
is dismissed, therefore displaying viewA
again. Before viewA
is displayed I want to be able to refresh the data though. Is there any way of doing this?
Upvotes: 0
Views: 649
Reputation: 1159
I guess that you dismiss the modalViewController or viewB in a method in viewA, if viewAcontroller is your delegate for viewBcontroller. In this same method, you only have to implement the table reload data you need, and this will be done before displaying viewA again.
I have that kind of code:
in viewBcontroller.h before the interface:
@protocol ViewBControllerDelegate <NSObject>
-(IBAction)closeViewBController;
@end
in viewBcontroller.m:
-(IBAction)closeView{
[[self parentViewController] performSelector:@selector(closeViewBController)];
}
In viewAcontroller.h:
@interface viewAcontroller : UIViewController <ViewBControllerDelegate>
{//....implementation here
and in ViewAController.m:
-(IBAction)closeViewBController{
[self dismissModalViewControllerAnimated:YES];
//code needed if NSUserDefault is modified
}
that is quite easy to write. Hope this will answer your question
Upvotes: 0
Reputation: 27147
In viewA's viewWillAppear call you refresh code.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// your refresh code
}
Upvotes: 1
Reputation: 19789
You can use presentingViewController
/parentViewController
(read the docs on these). But a better all round solution is to make the "parent" the delegate of your modal controller, and have the parent implement a protocol that the delegate conforms to.
An even better solution is to present the modal controller with the return code in blocks, but you'll have to roll your own solution for that, as Apple haven't given us one yet.
Upvotes: 0
Reputation: 52237
Via delegation:
the ViewAController should implement a protocol, that the ViewBController offers
@protocol ViewBControllerProtocol
/*
use full signatures here
*/
@end
@interface ViewBController{
}
@property (nonatomic, assign) id<ViewBControllerProtocol> delegate;
@end;
@interface ViewAController <ViewBControllerProtocol>{
}
@end;
@implemantation ViewAController
// implement the method defined in the protocol
@end
then you do
viewB.delegate = viewA
You'll find a sample code at github, where CheckTableController
would be ViewBController
and ShowFavoritesTableController
ViewAController
.
Upvotes: 0