データがモーダルから表示中のView Controllerに渡されるときにデリゲートが機能しています。しかし、表示側のビュー コントローラーは、モーダルから受け取ったデータを表示していません。私は他の投稿を見て、デリゲート/プロトコルメソッドを使用するように言っていますが、提示している 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