UIPopover和UITableView数据交换

| 我在UINavigationController中有一个UITableView。在导航栏上,我有一个名为添加的按钮。按下此按钮时,将显示一个UIPopoverController,用户可以在其中输入要添加的数据作为UITableView中的新行/单元格。我的问题是如何从UIPopover向UITableView添加新单元格?是否将数组数据传递给UIPopOver根控制器?     
已邀请:
我知道有两种解决方案。一种方法是将通知从弹出窗口发送到根控制器,并应用必要的代码来更新“ 0”方法中的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
}
抱歉,这有点长。我只是想确保自己彻底。希望能帮助到你     

要回复问题请先登录注册