为什么在制作自定义表格视图单元格时出列可重用单元格两次 [英] Why dequeue reusable cell twice in making custom table view cell

查看:32
本文介绍了为什么在制作自定义表格视图单元格时出列可重用单元格两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习使用故事板制作自定义表格视图单元格的教程.我拖动一个 UILabel 作为单元格的子视图并将其标记设置为 1.我有两个关于数据源代码的问题.

I am following a tutorial of making custom table view cell with storyboard. I drag a UILabel as subview of the cell and set its tag to 1. I have two questions regarding the data source code.

  1. 第二个出队语句的目的是什么?我知道这是一个 init 方法,而不是使用故事板来制作自定义单元格.

  1. What's the purpose of the second dequeue statement? I know it's an init method while not using storyboard to make the custom cell.

tableview 和 self.tableview 有什么区别?

What's the difference between tableview and self.tableview?

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    }
    NSDictionary *dToAccess = (self.tableView==tableView)?[self.arForTable objectAtIndex:indexPath.row] : [self.arForSearch objectAtIndex:indexPath.row];
    [(UILabel*)[cell viewWithTag:1] setText:[dToAccess valueForKey:@"name"]];
    [(UILabel*)[cell viewWithTag:2] setText:[dToAccess valueForKey:@"value"]];
    return cell;
}

推荐答案

出队两次不是必须的,这块代码被破坏了.

To dequeue twice is not necessary, this block of code is broken.

这篇关于为什么在制作自定义表格视图单元格时出列可重用单元格两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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