我让委托工作,因为数据正在从模式传递到呈现视图控制器。但是呈现视图控制器没有显示它从模式中接收到的数据。我查看了其他帖子,他们说要使用委托/协议方法,但没有解释呈现的 VC 如何/为什么刷新。我假设我的代表设置不正确。否则,刷新数据的方法是什么?我已经检查过了,viewWillAppear 和 viewDidAppear 没有被调用。
SCCustomerDetailVC.h(展示 VC)
#import "SCCustomersVC.h"
@interface SCCustomerDetailVC : UIViewController <SCCustomersVCDelegate>
@property (atomic, strong) SCCustomer *customer;
@property (strong, nonatomic) IBOutlet UIButton *changeCustomerButton;
- (IBAction)changeCustomerButtonPress:(UIButton *)sender;
@end
SCCustomerDetailVC.m(展示 VC)
- (IBAction)changeCustomerButtonPress:(UIButton *)sender
{
UINavigationController *customersNC = [self.storyboard instantiateViewControllerWithIdentifier:@"customersNC"];
SCCustomersVC *customersVC = (SCCustomersVC *)customersNC.topViewController;
customersVC.delegate = self;
[self presentViewController:customersNC animated:YES completion:nil];
}
//Protocol methods
- (void)passCustomer:(SCCustomer *)customer
{
self.customer = customer;
//At this point, self.customer has the correct reference
[self dismissViewControllerAnimated:YES completion:nil];
}
SCCustomersVC.h(模态 VC)
#import "SCCustomersVCDelegate.h"
@class SCCustomerDetailVC;
@interface SCCustomersVC : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
@property (weak, nonatomic) id <SCCustomersVCDelegate> delegate;
@end
SCCustomersVC.m(模态VC)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SCCustomer *customer = [self customerAtIndexPath:indexPath];
[self.delegate passCustomer:customer];
}
SCCustomersVCDelegate.h
@class SCCustomer;
@protocol SCCustomersVCDelegate <NSObject>
@optional
- (void)passCustomer:(SCCustomer *)customer;
@end