- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
团队,
我有 UITableView,其中包含 50 多个单元格。每个单元格的宽度为60。
当我滚动到 20 个单元格时,然后点击任何单元格
它给出单元格值上方的索引路径值而不是单击单元格值
在 CellForRowAtIndexPath 内部
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[[cell checkButton] addTarget:self action:@selector(checkButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)checkButtonAction:(id)sender
CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableview];
NSIndexPath *indexPath = [self.tableview indexPathForRowAtPoint:touchPoint];
UIButton *button = (UIButton *)sender;
}
如果选择的索引是 21,则给出索引 20,保持索引计数从零开始。
这个问题是在 iOS 10.1 iphone 7 plus 设备中观察到的,不是在模拟器 iPhone 7 plus iOS 10.1 (14B72) 中
调试值 {长度 = 2,路径 = 0 - 14}
NSIndexPath 路径应该是 0 - 15 但它给出了 0 - 14。
最佳答案
[YOURBUTTON addTarget:self action:@selector(METHODNAME:event:) forControlEvents:UIControlEventTouchDown];
按钮点击方法
-(IBAction)METHODNAME:(UIButton*)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:YOUR_TABLEVIEW];
NSIndexPath *indexPath = [YOUR_TABLEVIEW indexPathForItemAtPoint: currentTouchPosition];
// your requirement code
}
如果对此代码有任何疑问,请将您的评论放在答案中。祝你好运
快乐编码。
关于ios - UITableView selected indexpath 值给错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41217716/
最近想根据indexPaths删除单元格,所以函数的入参是[IndexPath]类型,需要根据把[IndexPath]拆分成几个数组indexPath.section,有什么简单的方法吗?例如 ind
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我有一个 TableViewController,其中包含使用 CoreData 的数据条目列表。我还有带 TextView 的 ViewController。我已经完成了对项目的添加、保存和删除等操
我正在编写一个 UICollectionViewLayout 子类。 我知道 Collection View 有多少个部分...numberOfSections。 我知道每个部分有多少项目...num
这是我的 collectionViewCell 图像。 我在 tableViewCell 中有 collectionView 并且在 collectionViewCell 中有一个按钮,它完全符合我的
这个问题在这里已经有了答案: Passing data between view controllers (45 个答案) 关闭 3 年前。 我在 UIViewController 中定义它并尝试在
我在我正在开发的应用程序中的表格单元格上设置长按手势时遇到了一些问题。我已经尝试了三种不同的配置,但还没有一种能够成功运行。 场景 1) 我将 UILongPressGestureRecognizer
在我更新到 Xcode 7.2 后,弹出一个错误提示“下标的使用不明确”: func tableView(tableView: UITableView, cellForRowAtIndexPath i
我在 UITaleViewCell 中有一个 UIImageView,我向 UIImageView 添加了一个点击识别器。 - (IBAction)ui_tapped:(UITapGestureRec
我正在尝试追踪应用程序中的严重崩溃。 我有一些代码可以有效地做到这一点: if let indexPath = self.tableView.indexPath(for: myTableViewCel
我有一个 UITableView,一个自定义单元格的自定义类和我的 ViewController swift: private var model_firma = [Firme]() var firm
我有一个 Tableview,显示一个包含 7 行的部分,我想要做的是,当我按第 0 行时,我将其发送到另一个 View ,表中的所有信息都是通过使用修复的代码加载的,我的问题是如何在“prepare
我注意到要禁用表格单元格的突出显示功能,您可以使用以下方法: override func tableView(tableView: UITableView, didSelectRowAtIndexPa
这个问题在这里已经有了答案: Issue Detecting Button cellForRowAt (3 个答案) 关闭 2 年前。 使用此代码,我只获得具有 indexpath.row 如何从中
我正在开发一个待办事项应用程序。在我的应用程序中,我按下复选框按钮来删除一行。我编写这段代码是为了将 indexPath.row 传递到我的复选框按钮中: cell.checkbox.tag = in
我有一个像这样的UIViewController: class ViewController { override func viewDidLoad() { super.vie
不知道你有没有遇到过这种情况,我用的是该函数 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPa
UITableViewController 的 numberOfSection 和 numberOfRowsInSection 被调用,但 cellForRow 没有。可能是什么原因 ?下面是 tab
我是 Stack Overflow 的新手,所以请保持温柔! 我正在设计一个应用程序,它从 firebase 检索对象并在 firebase 中显示它们。 我在这里配置firebase: func a
我手头有一个非常原始的问题,那就是当我将点击手势识别器添加到我的自定义单元格时,我无法调用 didSelectRowAt 方法。 我的代码如下: import UIKit class Language
我是一名优秀的程序员,十分优秀!