0

tableViewを持つviewControllerの上に表示されるmodalViewControllerがあります。ユーザーが modalViewController のボタンをクリックすると、viewController 内の tableView を次のようにリロードします。

[tableView1 reloadData]; 

tableView をリロードする必要がない場合 (つまり、ユーザーが戻るボタンをクリックして tableView に戻る場合) に呼び出されるため、viewDidAppear または viewWillAppear メソッドにリロードを入れたくありません。

これを行う方法はありますか?

4

6 に答える 6

2

これは古典的なデリゲートパターンの問題です。モーダルビューコントローラでは、それを提示している現在のビューコントローラへのデリゲート参照が必要です。

//Modal
@protocol ModalVCDelegate
- (void)tappedBackButton;
@end

@class ModalVC: UIViewController
@property id<ModalVCDelegate> delegate;
@end

@implementation
- (void)backButtonTapped:(id)sender
{
    if (self.delegate) 
        [self.delegate tappedBackButton];
}
@end

次に、提示するVCで、このデリゲートメッセージを処理するだけです。

//Parent VC
- (void)showModal
{
    ModalVC *vc = [ModalVC new]; 
    vc.delegate = self;
    //push
}

- (void)tappedBackButton
{
    [self.tableView reloadData];
    //close modal
}
于 2013-03-04T05:57:54.310 に答える
2

試す

1 ) reloads.table data

2) 背面をbuttonクリックして呼び出します。

于 2013-03-04T05:33:24.093 に答える
1

デリゲートを使用できます。それがもっと難しいと思うなら、代わりにを使うことNSNotificationCenterです。TableViewを更新するための承認済みの回答を確認できます。これは本当に短く、簡単で理解しやすい方法です。

于 2013-03-04T05:55:53.553 に答える
0

これを使ってみてください

ボタンを作成してこのボタンをクリックすると、データをリロードできます。このボタンはカスタムを作成し、バックグラウンドで使用します。

  - (IBAction)reloadData:(id)sender
    {
         [tblView reloadData];
    }
于 2013-03-04T05:52:08.733 に答える
0

以下の方法のような通知の使用:-

NSNotificationCenteryourViewControllerのViewdidLoadMehodで作成します

- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(ReloadDataFunction:)
                                                     name:@"refresh"
                                                   object:nil];

  [super viewDidLoad];

}
-(void)ReloadDataFunction:(NSNotification *)notification {

    [yourTableView reloadData];

}

これで、modelViewController BackButtonからこの通知を呼び出すことができます。または、次のコード行を配置するように、この更新通知を呼び出さないようにすることができます。

[[NSNotificationCenter defaultCenter] postNotificationName:@"refresh" object:self];

注: postNotificationName:@"refresh"これは特定の通知のキーです

于 2013-03-04T05:52:48.617 に答える
-2
You can use NSNotification to refresh table on ViewController.

Inside viewController :

-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}

Write code in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(reloadMainTable:) 
        name:@"ReloadTable"
        object:nil];




- (void) reloadMainTable:(NSNotification *) notification
{
  [tableView reload];
}


Inside ModelViewController:
[[NSNotificationCenter defaultCenter] 
        postNotificationName:@"ReloadTable" 
        object:nil];

Here you can also send custom object instead of nil parameter. But be care full about removal of NSNotification observer.
于 2013-03-04T06:01:16.257 に答える