2

私が現在iPadアプリで直面しているこの問題に対処する方法について、誰かがいくつかの提案/ポインターを提供できるかどうかを確認したかった。以下に説明しているグラフィックへのリンクを示し ますhttp://www.yogile.com/dsruyzk7/41m/share/?vt=QANtu4j

基本的に、2つの子ViewControllerを含むparentViewControllerがあります。子1にはUITableViewがあり、子2にはカスタムUIViewがあります。子1のUITableviewから子2のカスタムUIViewにdidSelectRowAtIndexPathから情報をロードできます。子2にデータが表示された後、処理を行います。処理が完了したら、子1のUITableViewを更新して、新しい/更新されたデータがUITableViewに表示されるようにする必要があります。子1でデリゲートを作成しようとしましたが、機能していませんでした。何か間違った設定をした可能性があります。したがって、ヘルプの提案をいただければ幸いです。

ありがとう

子2ViewControllerの.h

@class Child2ViewController;

@protocol child2Delegate <NSObject>
- (void)refreshTable:(Child2ViewController*)controller passedDict:(NSDictionary *)dict;

@interface Child2ViewController:UIViewController<UITableViewDataSource, UITableViewDelegate> {
    UITableView *myTableView;
    id<child2Delegate> delegate;
    Child1ViewController *child1VC;
}

@property (nonatomic, weak) id<child2Delegate> delegate;
…
…

@end

子2ViewControllerの.m

@synthesize delegate;
…
..
..
#after all the processing is done we are ready to refresh the view
#updatedDictForTableView is basically a NSDictionary and has the updated data needed
#for the UITableview on child1VC.

-(void)processData {
    child1VC.delegate = self
    NSLog(@"Dump the updated Data : %@", updatedDictForTableView);
    [delegate refreshTable:self passedDict:updatedDictForTableView;
}

Child1ViewControllerの.h

@interface Child1ViewController : UIViewController <child2Delegate> {
    ….
    ….
    ..
}

Child1ViewControllerの.m

- (void)refreshTable:(Child2ViewController*)controller passedDict:(NSDictionary *)dict {
    NSLog(@"dump dict %@", dict);
    [myTableView reloadData];

}
4

2 に答える 2

1

これを行うには、親テーブルビュープロパティを子クラスに追加します(ここでは、詳細ビューまたはDetailViewControllerと見なされます)。

@interface DetailViewController : UIViewController {
...
UITableView *parentTableView;
...
}
@property (nonatomic, retain) UITableView* parentTableView;

次に、そのプロパティを子1のどこかに設定してから、子2に何かを表示します。たとえば、viewWillAppearのようになります。

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.detailViewController.parentTableView = self.tableView;
}

これで、子2テーブルビュー内に子1テーブルビューをリロードする準備が整いました...

于 2012-09-14T01:58:07.407 に答える
1

委任なしでそれを行うことができます。NSNotificationcenterを使用して、nsdictionaryの値を含む通知を送信します。exple:

  // in child1 ( in viewDiDLoad function )
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FunctionToReloadData:) name:@"ProcessDone" object:nil];

  // remove the listnerin child1 ( in viDidUnload )
[[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"ProcessDone"];

 //in child2 ( in the end of your processData function )
 [[NSNotificationCenter defaultCenter] postNotificationName:@"ProcessDone" object:nil userInfo:updatedDictForTableView ];


 //in child1
 -(void) FunctionToReloadData:(NSNotification *)notification
 {
    // get the sended dictionary
    NSDictionary *tmpDic = [notification userInfo];
     .
     .
     [tableView reloadData];

 }
于 2012-09-16T20:20:08.170 に答える