-2

是否可以从 web 服务器中为 tableview 的每个第 5 行提取图像,而不会破坏 cellforrowatindexpath 方法的正常运行?谢谢

4

2 回答 2

2

检查tableView:cellForRowAtIndexPath:是否indexPath.row可被 5 整除,如果为真则以不同方式处理单元格(例如其他背景图像,...)。

于 2012-07-18T17:29:19.270 回答
2

示例代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Here is the magic.
    if (!indexPath.row % 5 == 0)
    {
        // Do your usual code
    }
    else
    {
        // Do alternate code (loading background image)
    }
    return cell;
}
于 2012-07-18T19:44:38.040 回答