【发布时间】:2012-09-14 01:23:32
【问题描述】:
想看看是否有人可以就如何解决我目前在 iPad 应用程序中遇到的这个问题提供一些建议/指示。这是我在下面描述的图形的链接 http://www.yogile.com/dsruyzk7/41m/share/?vt=QANtu4j
基本上我有一个包含 2 个子视图控制器的 parentViewController。孩子 1 有一个 UITableView 和 Child 2 有一个自定义 UIView。我能够从 didSelectRowAtIndexPath 将 Child 1 上的 UITableview 的信息加载到 Child 2 上的自定义 UIView。数据出来后 显示在孩子 2 我做一些处理。处理完成后,我需要更新 Child 1 上的 UITableView 以便新的/更新的数据 显示在 UITableView 上。我尝试在 Child 1 上创建一个代表,但没有工作,也许我设置了错误。因此,任何帮助建议将不胜感激。
谢谢
.h on Child 2 ViewController
@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
.m on Child 2 ViewController
@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;
}
.h in Child1 ViewController
@interface Child1ViewController : UIViewController <child2Delegate> {
….
….
..
}
.m in Child1 ViewController
- (void)refreshTable:(Child2ViewController*)controller passedDict:(NSDictionary *)dict {
NSLog(@"dump dict %@", dict);
[myTableView reloadData];
}
【问题讨论】:
-
你给代表打电话了吗?发布一些代码,以便我们更清楚地看到您在做什么。
-
抱歉延迟回复。刚刚添加了一些关于我如何设置委托和调用它们的代码。再次感谢您花时间研究这个问题。