【问题标题】:UIPopover and UITableView data exchangeUIPopover 和 UITableView 数据交换
【发布时间】:2011-05-19 20:36:48
【问题描述】:

我在 UINavigationController 中有一个 UITableView。在导航栏上,我有一个名为 add 的按钮。当按下此按钮时,它会显示一个 UIPopoverController,用户可以在其中输入要添加为 UITableView 中的新行/单元格的数据。我的问题是如何从 UIPopover 向 UITableView 添加一个新单元格?我是否将数组数据传递给 UIPopOver 根控制器?

【问题讨论】:

  • 我想这取决于您的表格视图的数据源。如果您在 iPhone 上使用模态视图来做同样的事情,它应该与 iPad 上的弹出框类似。
  • 是的,它与模态视图相同。问题是如何?当你说它取决于数据源时,这是什么意思?我希望能够从弹出窗口中执行 insertRowsAtIndexPath .. 这是主要目标。

标签: iphone objective-c ipad uitableview uipopover


【解决方案1】:

据我所知,有两种解决方案。一种方法是从弹出框向根控制器发送通知,并应用必要的代码来更新 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
}

抱歉,有点长。我只是想确保我是彻底的。希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 2014-07-11
    相关资源
    最近更新 更多