11

データがモーダルから表示中の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
4

2 に答える 2

6

私はあなたがほぼそこにいると思います。編集 - iOS>5 では viewWillAppear の動作が異なることをここで学びました。最初のプレゼンテーションでそれを行う必要があるため、ビューがモデルの状態でビューを更新するように表示する必要があります。

また、モーダル VC またはデリゲート メソッド内から呼び出すこともできます。したがって、View Controllerのモデル状態でビューを更新するコードをviewWillAppearに追加してください...

// SCCustomerDetailVC.m
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // making up an IBOutlet called someLabel
    // making up a model method (description) that returns a string representing your model
    self.someLabel.text = [self.customer description];
}

次に、提示された VC またはデリゲートから、viewViewWillAppear を呼び出します。

- (void)passCustomer:(SCCustomer *)customer
{
    self.customer = customer;
    [self viewWillAppear:YES];
    [self dismissViewControllerAnimated:YES completion:^{}];
}
于 2013-03-18T05:23:55.060 に答える
3

「顧客」を設定した後、UI をリロードする必要があります。

- (void)passCustomer:(SCCustomer *)customer
{
    self.customer = customer;

    //At this point, self.customer has the correct reference

    [self dismissViewControllerAnimated:YES completion:^{
            // reload your UI here or call a method which will reload your ui
            // e.g. for tableView it will be [tableView reload];
        }];
}
于 2013-03-18T05:23:24.100 に答える