【问题标题】:UITableView reuse QuestionsUITableView 复用问题
【发布时间】:2016-01-29 03:08:39
【问题描述】:

关于UITableView重用,当有多个不同的Cell时,用不同的标识符区分好还是用一个标识符和Cell子Views remove,重新添加内容好,如果Cell很多的情况下,这些可重用的,什么样的具体的访问规则,当一个标识符在队列上的位置是如何去掉的高手解答,谢谢

_testTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_testTableView.dataSource = self;
_testTableView.delegate = self;
[_testTableView setRowHeight:80.];
[self.view addSubview:_testTableView];

[_testTableView registerClass:[TestTableViewCell class] forCellReuseIdentifier:testKeyOne];
[_testTableView registerClass:[TestTwoTableViewCell class] forCellReuseIdentifier:testKeyTwo];

//一种方式 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//one
if(indexPath.row < 15){

    TestTableViewCell * oneCell = [tableView dequeueReusableCellWithIdentifier:testKeyOne forIndexPath:indexPath];

    return oneCell;

}else{

    TestTwoTableViewCell * oneCell = [tableView dequeueReusableCellWithIdentifier:testKeyTwo forIndexPath:indexPath];

    return oneCell;

}

return nil;

}

两种方式:

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

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:testKeyOne forIndexPath:indexPath];

for(UIView * view in cell.subviews){

    [view removeFromSuperview];

}

//[cell addSubview:];

return cell;

}

一种或两种,或者其他更好的方式,以及原本特定的重用,进入重用并取出队列顺序的顺序

【问题讨论】:

  • 请正确解释,你到底想做什么......
  • 对不起,我没看懂你的问题,请把你的问题说清楚,并请使用标点符号(例如问号)。

标签: ios uitableview


【解决方案1】:

您想选择选项一。表视图数据源不应在表视图单元格中添加或删除视图。这太混乱了。

另一种选择是只有一个单元子类,但对子类进行编码以根据需要隐藏和显示视图。我不会让它添加和删除视图。那是更复杂的代码和更昂贵的时间,当你试图在滚动时获得高帧率时,这不是很好。

【讨论】:

    猜你喜欢
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 2011-07-23
    • 2021-11-30
    • 2011-02-03
    • 2012-05-26
    相关资源
    最近更新 更多