我在UINavigationController中有一个UITableView。在导航栏上有一个名为add的按钮。当按下该按钮时,它显示一个UIPopoverController,用户可以在其中输入要作为UITableView中的新行/单元格添加的数据。我的问题是如何从UIPopover向UITableView添加新的单元格?我是否要将数组数据传递给UIPopOver根控制器?
发布于 2011-05-20 05:37:12
据我所知,有两种解决方案。一种方法是从popover向根控制器发送通知,并应用必要的代码来更新handleNotification方法中的tableView。
另一个,也是我个人使用的一个,是为popover设置一个委托协议。你必须像这样设置它:
@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> {然后在根视图控制器实现文件中,在实例化popover委托时分配它。例如:
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
}对不起,这有点长。我只是想确保我做的很周到。希望能有所帮助
https://stackoverflow.com/questions/6064577
复制相似问题