首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIPopover和UITableView数据交换

UIPopover和UITableView数据交换
EN

Stack Overflow用户
提问于 2011-05-20 04:36:49
回答 1查看 1K关注 0票数 2

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-20 05:37:12

据我所知,有两种解决方案。一种方法是从popover向根控制器发送通知,并应用必要的代码来更新handleNotification方法中的tableView。

另一个,也是我个人使用的一个,是为popover设置一个委托协议。你必须像这样设置它:

代码语言:javascript
复制
@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

然后,在根视图控制器头文件中,您需要添加委托

代码语言:javascript
复制
@interface RootViewController .... <PopoverDelegate> {

然后在根视图控制器实现文件中,在实例化popover委托时分配它。例如:

代码语言:javascript
复制
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];

最后,将协议方法添加到代码中的某处

代码语言:javascript
复制
- (void)addNewCell {
    // do what you want with the tableView from here
}

对不起,这有点长。我只是想确保我做的很周到。希望能有所帮助

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6064577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档