- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Controller 类中,我正在实现 TableView 数据源委托(delegate)方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"In cell for row at index path %i ", indexPath.row);
// a bunch of other typical stuff
}
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
UITableViewCell *cell = [self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSLog(@"About to send message to tableView:cellForRowAtIndexPath:indexPathForRow:inSection");
MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *) [self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
MCSwipeTableViewCell *theOtherCell = (MCSwipeTableViewCell *) [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSLog(@"Here is the call on self %@", cell);
NSLog(@"Here is the delegate cell %@", theOtherCell);
NSLog(@"Here is my reference %@", self);
NSLog(@"Here is the table view delegate %@", self.tableView.delegate);
2014-06-13 15:20:41.601 krow[28823:70b] Here is the call on self <MCSwipeTableViewCell: 0xa3eda00; baseClass = UITableViewCell; frame = (0 0; 320 44); gestureRecognizers = <NSArray: 0x8d82dc0>; layer = <CALayer: 0x8d82de0>>
2014-06-13 15:20:41.601 krow[28823:70b] Here is the delegate cell <MCSwipeTableViewCell: 0xc43fa00; baseClass = UITableViewCell; frame = (0 0; 320 220); autoresize = W; gestureRecognizers = <NSArray: 0xa8be640>; animations = { position=<CABasicAnimation: 0x8d79040>; }; layer = <CALayer: 0xa87d070>>
2014-06-13 15:20:41.601 krow[28823:70b] Here is my reference <KrowInboxTableViewController: 0x8c779c0>
2014-06-13 15:20:41.601 krow[28823:70b] Here is the table view delegate <KrowInboxTableViewController: 0x8c779c0>
最佳答案
对于初学者,cellForRowAtIndexPath:
您有意调用的方法不会调用委托(delegate)来创建新单元格。与委托(delegate)方法不同 tableView:cellForRowAtIndexPath:
它实际上创建或出列一个单元格并将其返回到 TableView ,cellForRowAtIndexPath:
方法只是在那里为您提供对现有单元格的引用。文档在返回值的描述中支持了这一点:An object representing a cell of the table or nil if the cell is not visible or indexPath is out of range.
.
再说一遍,tableview 自己调用的委托(delegate)方法是用来创建一个单元格的,而您正在调用的方法只是在那里抓取一个现有的可见单元格,而不需要创建或出列任何东西。
至于下一点,问题在于您正在调用 tableview 应该调用的方法,该方法将创建或出列一个新单元格,而不是返回一个已经可见的单元格。您永远不应手动调用此方法。您使用的第一种方法cellForRowAtIndexPath:
是获取现有可见单元格的正确方法。除此之外,如果这不能解决您的问题,您需要提供有关您实际尝试完成的更多信息。
关于ios - UITableViewController tableView :cellForRowAtIndexPath returns wrong row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24214581/
我有一个问题,当从 tableView:cellForRowAtIndexPath 调用时,cellForRowAtIndexPath 总是返回 nil: 问题是我实际上是在 tableView:ce
假设 self.tableView 是我创建的 UITableView 实例变量,任何人都可以解释这两个语句之间的区别吗?两者在语法上都是正确的,而且我认为两者都会做同样的事情:在 self.tabl
我对 iPhone 开发还很陌生。因此,如果我问一些非常简单的问题,请耐心等待。 在我的应用程序中,我有多个 View (即 .xib 文件)。单击主视图(CouponWebsiteViewContr
Application Specific Information: *** Terminating app due to uncaught exception 'NSRangeException',
我正在显示通过 Storyboard 初始化的动态表格 View 。 没什么特别的,只是用文本标签初始化 3 个单元格。 以下是实际发生的情况: 2014-08-15 12:39:19.909 Pop
我正在开发一个应用程序,我有一个 UITableView,它使用 tableView 方法填充了一个 NSMutableArray:cellForRowAtIndexPath:,它工作正常,但问题是我
我在两个 View 之间沟通时遇到了麻烦。我的目标是向我的 NSMutableArray 添加一个新对象.感谢 stackoverflow 上可爱的人,他们已经修复了。现在我有另一个问题。 即使我能够
我有一个奇怪的错误。我有一个带有静态单元格的分组 UITableView,我想在每个部分下添加一个白色阴影。我考虑的方法是为一个部分中的每个最低单元格添加阴影。 所以在 viewDidAppear 中
每当我滚动我的 tableview 时,它都非常滞后。我认为这与我加载细胞的方式有关。我尽可能使用 UINib (5.0+),同时仍然提供向后兼容性。然后我从 NSArray 中的 NSDiction
我不明白cellForRowAtIndexPath函数的indexPath参数始终为0。我的表当前有7行。我的表格显示的是表格第一行的7倍。是什么导致indexPath始终为零? @implement
我正在开发一个使用表格 View 的 ToDoList iOS 应用程序。单元格内容(UITableCellView)由 nsmutablearray 的实例变量填充。 当我添加一个新的 ToDoIt
所以我有快速的代码,可以创建一个配置文件列表,并允许个人对其进行过滤和排序以及单击它们。就像地址簿一样。它以主/详细信息格式设置,其中主信息是人员列表,详细信息是个人。我还有一个来自 master 的
完整代码如下: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *
我有两个实体:日记帐和帐户。这种关系是一对多的:Journal 只有一个 Account。账户有很多日记账。我想根据每个帐户的日记显示总计,但我不知道如何操作。目前我为每个帐户获得的总额是相同的: 在
我的 cellForRowAtIndexPath 并非每次都会触发我将 dataSource 和 delegate 设置给文件所有者。我还设置了引用 socket 。我还尝试了 tbl.delegat
我的项目: 我的项目中有一个 UITableView。每个 UITableViewCell 都有一个 UITextView 作为 subview 。当用户点击“添加”按钮时,我需要再添加一个带有 UI
我的单元格中的数据在 cellforrowatindexpath 中混淆了。我更改了标签的文本颜色和文本,但即使 isComplete 值更改,单元格颜色和文本也会随机更改。 例如,当我滚动表格 Vi
免责声明:我使用的是 iOS 8,因此这可能是一个错误。 我正在尝试在特定事件发生后以编程方式编辑 UITableView 中特定 IndexPath 处单元格的背景颜色。我使用以下代码: UITab
填充 TableView 时出现奇怪的错误。这是我做过无数次的事情,但现在我对一些可能非常简单的事情感到困惑。也许我只是醒得太久了。 我有一个名为 riverGauge 的对象,它负责从 Web 服务
我的应用程序中有一个 tableView,当用户点击该单元格时,我需要它转到另一个 View Controller ,该 Controller 提供有关他们单击的单元格的更多详细信息。当我尝试使用 获
我是一名优秀的程序员,十分优秀!