0

我想知道是否有办法在整个程序的任何地方调用 tableview 函数。我的意思是我想调用这个函数:

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

在我的代码中的任何地方。有没有使用 self 功能或任何东西,或者如果它可能的话?谢谢。

4

3 回答 3

2

你当然可以。您只需能够将NSIndexPath对象传递给它,如下所示:

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

一旦cellForRowAtIndexPath返回您的单元格对象,您就可以访问其属性等,例如:

cell.backgroundView.alpha = 0.0;

此外,如果您使用的是自定义 UITableViewCell,则可以通过类型转换调用返回自定义单元格:

MyCustomCellClass *cell = (MyCustomCellClass *)[self.tableView cellForRowAtIndexPath:indexPath];
于 2013-02-11T03:39:06.713 回答
1

你可以这样做:

  // First do modifications in the datasource for table     
    // And then you can reload the specific row like this:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

而你的 cellForRowAtIndexPath 没有调用的原因可能是因为你没有设置委托或者 UI 上没有可见的行来显示,因为 Table 为屏幕上可见的行调用了这个函数,所以也要检查你的表格的框架。

于 2013-02-11T04:59:04.227 回答
1

你可以调用 [tableview reloadData]; 这将调用索引路径处的行单元格。

于 2013-02-11T04:15:58.847 回答