cellForRowAtIndexPath如何工作? [英] How does cellForRowAtIndexPath work?

查看:127
本文介绍了cellForRowAtIndexPath如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了苹果文档,对于像我这样的 Objective-C 这样的初学者来说,这是不可理解的。我正在尝试按照链接

c> c>来实现多列 UITableView a>示例,它只是不起作用所以我需要理解 cellForRowAtIndexPath 的工作方式,因为对我个人而言,这种方法看起来相当复杂。

I HAVE READ apple documentation and it's not understandable for such a beginner in Objective-C as me. I'm trying to implement multicolumn UITableView following this link example and it just doesn't work so i need to comprehend how cellForRowAtIndexPath work, cause for me personally this method seems pretty complicated.

1)它返回什么? 的UITableViewCell ?但为什么它看起来如此奇怪?

1) What does it return? UITableViewCell? But why does it look so odd?

-(UITableViewCell *)tableView:(UITableView *)tableView 




  • 那是什么?你可以解释一下吗?

  • 2)它是如何被调用的,更重要的是如何将它连接到某个的UITableView ???如果我有两个 UITableView 的名为 firstTableView secondTableView 并且我希望它们不同(以不同方式执行 cellForRowAtIndexPath )?我应该如何将 UITableViews 链接到此

    2) How does it get called and what is more important how am i to connect it to a certain UITableView??? What if i have two UITableView's named firstTableView and secondTableView and i want them to be different (to perform cellForRowAtIndexPath differently)? How am i supposed to link my UITableViews to this

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    方法接受 NSIndexPath ,而不是 UITableView 。我该怎么办?

    the method accepts NSIndexPath, not UITableView. What am i gonna do?

    推荐答案

    1)该函数返回一个表视图的单元格是吗?因此,返回的对象的类型为 UITableViewCell 。这些是您在表格行中看到的对象。对于表视图,此函数基本上返回一个单元格。
    但你可能会问,函数如何知道哪一行返回哪一行,这在第二个问题中得到了解答

    1) The function returns a cell for a table view yes? So, the returned object is of type UITableViewCell. These are the objects that you see in the table's rows. This function basically returns a cell, for a table view. But you might ask, how the function would know what cell to return for what row, which is answered in the 2nd question

    2) NSIndexPath 基本上是两件事 -

    2)NSIndexPath is essentially two things-


    • 你的部分

    • 你的行

    因为您的表可能被划分为多个部分,并且每个部分都有自己的行,所以 NSIndexPath 将帮助您准确识别哪个部分和哪个行。它们都是整数。如果你是初学者,我会说只试一个部分。

    Because your table might be divided to many sections and each with its own rows, this NSIndexPath will help you identify precisely which section and which row. They are both integers. If you're a beginner, I would say try with just one section.

    如果你实现了 UITableViewDataSource 视图控制器中的协议。一种更简单的方法是添加一个 UITableViewController 类。我强烈推荐这个,因为Apple为您编写了一些代码,可以轻松实现可以描述表格的功能。无论如何,如果您选择自己实现此协议,则需要创建一个 UITableViewCell 对象并将其返回到任何行。看看它的类参考,以了解可重用性,因为表视图中显示的单元格一次又一次地重复使用(这是一个非常有效的设计btw)。

    It is called if you implement the UITableViewDataSource protocol in your view controller. A simpler way would be to add a UITableViewController class. I strongly recommend this because it Apple has some code written for you to easily implement the functions that can describe a table. Anyway, if you choose to implement this protocol yourself, you need to create a UITableViewCell object and return it for whatever row. Have a look at its class reference to understand re-usablity because the cells that are displayed in the table view are reused again and again(this is a very efficient design btw).

    至于何时有两个表视图,请查看方法。表视图传递给它,所以你不应该有这个问题。

    As for when you have two table views, look at the method. The table view is passed to it, so you should not have a problem with respect to that.

    这篇关于cellForRowAtIndexPath如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆