UIPopover 和 UITableView 数据交换

发布于 2024-11-08 05:54:07 字数 208 浏览 0 评论 0原文

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

I have a UITableView in a UINavigationController. On the navigation bar I have a button called add. When this button is pressed it presents a UIPopoverController, where user can input data to be added as a new row/cell in the UITableView. My issue is how can I add a new cell to the UITableView from the UIPopover? Do I pass in the array data to the UIPopOver root controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅过去的我 2024-11-15 05:54:07

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

抱歉,有点长。我只是想确保我做得彻底。希望有帮助

There are two solutions to this that I'm aware of. One would be to send a notification from the popover to the root controller and apply the necessary code to update the tableView in the handleNotification method.

The other, one that I personally use, is to set up a delegate protocol for the popover. You'll have to set it up something like this:

@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

Then in your root view controller header file, you need to add the delegate

@interface RootViewController .... <PopoverDelegate> {

Then in your root view controller implementation file, assign the popover delegate when you instantiate it. For example:

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];

Finally, you'll add your protocol method somewhere in the code

- (void)addNewCell {
    // do what you want with the tableView from here
}

Sorry that's a bit long. I just wanted to make sure I was thorough. Hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文