Tôi có đại biểu làm việc khi dữ liệu đang được chuyển từ phương thức sang trình điều khiển xem trình bày. Nhưng bộ điều khiển xem trình bày không hiển thị dữ liệu mà nó nhận được từ phương thức. Tôi nhìn vào các bài viết khác và họ nói để sử dụng phương thức đại biểu/giao thức, nhưng không giải thích làm thế nào/tại sao trình bày VC làm mới. Tôi giả định rằng đại biểu của tôi được thiết lập không chính xác. Nếu không, phương pháp làm mới dữ liệu là gì? Tôi đã kiểm tra và viewWillAppear và viewDidAppear không được gọi.Làm mới dữ liệu trong UIViewController sau khi loại bỏ bộ điều khiển chế độ xem được trình bày của nó qua đại biểu
SCCustomerDetailVC.h (Trình bày 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 (Trình bày 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 (Modal VC)
#import "SCCustomersVCDelegate.h"
@class SCCustomerDetailVC;
@interface SCCustomersVC : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
@property (weak, nonatomic) id <SCCustomersVCDelegate> delegate;
@end
SCCustomersVC.m (Modal 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
bạn đã làm gì sau khi nhận được tham chiếu chính xác trong đại biểu của bạn. – Zen
@Zen Yup, tôi xin lỗi vì đã làm phiền tất cả các bạn vì điều này. Vì lý do nào đó, tôi nghĩ rằng nó sẽ "kỳ diệu" cập nhật vào đêm cuối cùng của chính mình trong trạng thái mệt mỏi của tôi. Tôi cần phải thêm mã để cập nhật nó. – guptron