- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
关于 MVC 范例的事情是你的 View 不应该知道你的模型。我有一个自定义的 TableCellView,这意味着它没有直接 View Controller 。它属于一个TableView。我的 tableView 当然有一个 Controller ,MyPetTableViewController。
无论如何,我的 CustomTableViewCell 有许多按钮和 ImageView,它们中的每一个都可以点击。根据单击哪个按钮/imageView,我需要:转到不同的选项卡 View ,或显示模态。如果我只是听表格行,那么 Controller 的工作就很简单了。但是如何让 Controller 监听表格单元格中的事件呢?我已经考虑过在 MyPetTableViewController 中使用 touchesEnded:withEvent
但是我不知道有问题的索引。所以我真的需要知道:单击了哪个表行中的哪个 View ?
最佳答案
这是我最终实现解决方案的方式
我通过从 Storyboard拖动到我的 CustomTableViewCell 的 .h
文件来创建 IBOutlets。 (通常我的做法是将 IBOutlets 保存在 .m
文件中,但由于解决这个问题需要将它们公开,所以我不得不将它们放在 .h
文件中) .
在实现我的 TableView 数据源和委托(delegate)方法的 Controller 中,在方法 tableView:cellForRowAtIndexPath:
中,我设置了按钮的目标。例如。 [cell.imageButtonOne addTarget:self action:@selector(userClicksButtonOne:) forControlEvents:UIControlEventTouchUpInside]
然后作为最后一步,我将 userClicksButtonOne
实现为
代码:
- (void) userClicksButtonOne:(id)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
if (indexPath != nil)
{
...
}
}
关于ios - iOS View TableViewCell 中的面向对象编程问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24973052/
[将数据从一个 TableViewCell 传输到另一个 TableViewCell][1] 我有 CountriesViewController 和 tableView ,其中是不同国家/地区的列表
我的 TableView 里面有 3 个 TableViewCell。 第一个 TableViewCell 有:标签 第二个 TableViewCell 有:TextField 第三个 TableVi
我不确定这是否是一个奇怪的设置,但我有两个自定义 tableView 单元格 - 手机手机 电子邮箱 在 PhoneCell 中,我有两个文本字段,这些文本字段中有一些值。在 EmailCell 中,
所以我有一个 ExpyTableView 类型的 mainTableView ( https://github.com/okhanokbay/ExpyTableView )。一切都很好,我设法实现了它
据我了解,我无法使用 socket 连接将单元格中的按钮连接到我的 TableViewController。 不过,我可以使用操作连接将单元格中的按钮连接到我的 TableView。这是我巨大问题的根
我想在动态 UITableViewCell 中添加一个动态 UICollectionView,当 CollectionView 接收并准备 contentView 时,它会自动更新其高度。有什么好的方
I want different images under different heading //ViewController.swift var categories = ["Good Aft
我有以下表格 View : 当用户点击蓝色的 Pay Cash/Card 按钮时,他们会转到另一个 tableView。 我遇到的问题是;当用户单击按钮时,不会在委托(delegate)方法中捕获 t
我有一个带有自定义单元格的 TableView。单元格中的 subview 之一是 UIButton。当用户单击按钮时,我希望背景发生变化。我得到了所有的工作。但问题是,直到我将受影响的单元格滚动出屏
- (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerNib:[UINib nibWithNibName
我今天花了六个多小时研究并尝试创建动态单元,但没有成功。我也找到了一些很棒的教程。我做错了什么,希望有人能告诉我什么。 我的应用: table 开始是空的。单击添加按钮会显示一个模态 VC,其中有两个
请注意此代码。 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITa
我有一个 tableViewCell,总共包含 8 个图像,分为两个 block (每个 block 4 个图像)。这些图像会异步下载并存储到数组中,然后在 tableViewCell 的 cellF
运行我的弹出窗口时,代码显示在左上角,而不是显示在单击图标的同一位置,是否可以更改某些内容来纠正位置? 最佳答案 这是因为您已将 aView 的 CGRect 设置为 x 和 y 为 0。 如果您以编
我用 CustomTableViewCells 制作了一个应用程序。我在 MainStoryBoard 上设置了一个 UIButton。 我想在点击时更改按钮的图像。当我再次点击时,我希望按钮返回到原
我正在编写一个 iOS 应用程序。用户输入电影搜索关键字,它会从 omdbapi.com 获取数据并在表格 View 中显示电影。问题是该 TableView 单元格未正确显示。 项目网址: proj
我目前有一个表格 View ,其中加载的单元格中有一个 uicollectionview。我目前遇到了表格 View 单元格的两个问题。 1) TableView 中的第一个单元格应该具有紫色背景,但
我有一个 TableView,可以在其中加载自定义单元格。在自定义单元格中,有一个文本字段,当表格 View 填充自身时,该文本字段会加载自定义拨号盘并自行关闭。这个 float 数字键盘在初始化期间
这是我的主屏幕当单击单元格突出显示时,描述将转到下一个 View Controller ,并且单元格会突出显示,当我单击未突出显示的单元格时,因此单元格未突出显示,这意味着只有零索引单元格突出显示,没
我想以编程方式将两个文本字段添加到 tableViewCell 子类(稍后会详细介绍),但很难从 View Controller 访问文本字段。 我的 TableView 子类是: - (id)ini
我是一名优秀的程序员,十分优秀!