我在 UINavigationController 中有一个 UITableView。在导航栏上,我有一个名为 add 的按钮。当按下此按钮时,它会显示一个 UIPopoverController,用户可以在其中输入要添加为 UITableView 中的新行/单元格的数据。我的问题是如何从 UIPopover 向 UITableView 添加新单元格?我是否将数组数据传递给 UIPopOver 根控制器?
问问题
1015 次
1 回答
4
我知道有两种解决方案。一种是从弹出窗口向根控制器发送通知,并应用必要的代码来更新handleNotification
方法中的 tableView。
另一种是我个人使用的,是为弹出框设置一个委托协议。您必须进行如下设置:
@protocol PopoverDelegate
- (void)addNewCell; // you can add any information you need to pass onto this if necessary such as addNewCellWithName:(NSString *)name, etc.
@end
@interface MyPopoverViewController..... {
id <PopoverDelegate> delegate;
// the rest of your interface code;
}
@property (nonatomic, retain) id delegate;
// any other methods or properties;
@end
然后在你的根视图控制器头文件中,你需要添加委托
@interface RootViewController .... <PopoverDelegate> {
然后在您的根视图控制器实现文件中,在您实例化它时分配弹出框委托。例如:
MyPopoverViewController *vc = [[MyViewController alloc] init];
vc.delegate = self; // this is where you set your protocol delegate
myPopover = [[UIPopoverController alloc] initWithContentViewController:vc];
myPopover.delegate = self;
[vc release];
最后,您将在代码中的某处添加您的协议方法
- (void)addNewCell {
// do what you want with the tableView from here
}
抱歉有点长。我只是想确保我是彻底的。希望能帮助到你
于 2011-05-19T21:37:12.213 回答