Call Function in a ViewController from UITableViewCell
2015-12-17 08:46
507 查看
http://stackoverflow.com/questions/32068689/call-function-in-a-viewcontroller-from-uitableviewcell
How can I call a function of a
a custom tableview cell of a
that
SWIFT)?
There are few ways you can do that
Delegation (create
a protocol delegate uitableViewcell) set view controller as delegate of
then from cell call
Post notification from the cell and register observer for that notification inside view controller view
more detail
Keep a weakReference of viewController inside UITableViewCell, means create a property
Add observer on a key path aka KVO (this
will call a method in view controller when a property changes its value) may be not necessary for your scenario
How can I call a function of a
ViewControllerfrom
a custom tableview cell of a
UITableViewin
that
ViewController(using
SWIFT)?
There are few ways you can do that
Delegation (create
a protocol delegate uitableViewcell) set view controller as delegate of
UITabelVeiwCelland
then from cell call
self.delegate.whatEverDeelgate()
Post notification from the cell and register observer for that notification inside view controller view
NSNotificationCenter.defaultCenter().addObserver(self, selector: "nameOfSelector", name: "Name Of Notification", object: nil)and then from tableView cell postNotification, but make sure you want to removeObserver as well, visit this link for
more detail
Keep a weakReference of viewController inside UITableViewCell, means create a property
@weak var viewController:YourViewcontrollerand use this to call method on view controller (Not recommended)
Add observer on a key path aka KVO (this
will call a method in view controller when a property changes its value) may be not necessary for your scenario
相关文章推荐
- UI之tableViewEdit(删除,添加,插入)
- What skills are required for machine-learning jobs?
- Unable to build the default ValidatorFactory
- [LeetCode317]Shortest Distance from All Buildings
- MUI 个推
- UIAlertController中UIAlertControllerStyleActionSheet与PickerView选择器的结合使用
- iOS中文API之UIResponder介绍
- 阿里巴巴开源项目 Druid 负责人温少访谈
- 【UESTC】2015 UESTC Training for Data Structures
- 阿里巴巴高新能数据源com.alibaba.druid.pool.DruidDataSource的jar包配置
- android123 zhihuibeijing 新闻中心-新闻 页签 ViewPagerIndicator实现
- UINavigationController 改颜色
- UIScrollView
- 正确勾选BarTender中True Type字体警告选项
- build diff: /../Podfile.lock: No such file or dire
- Unable to satisfy the following requirements
- BlockingQueue接口
- windows 查看进程命令tasklist, net user, query user
- 经验之谈—自定义tabbar(继承于UITabBar)
- IO基础-UITabBarController