Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 具有不同功能的唯一UITableViewCell_Ios_Uitableview - Fatal编程技术网

Ios 具有不同功能的唯一UITableViewCell

Ios 具有不同功能的唯一UITableViewCell,ios,uitableview,Ios,Uitableview,在我的项目中,需要将每个UITableViewCell显示为唯一的。假设有10个单元,那么所有10个单元都将有不同数量的子视图与其关联。为了实现这一点,我每次都要创建新的单元格,这意味着我没有做dequeCell:。每次我分配新手机时 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell =

在我的项目中,需要将每个UITableViewCell显示为唯一的。假设有10个单元,那么所有10个单元都将有不同数量的子视图与其关联。为了实现这一点,我每次都要创建新的单元格,这意味着我没有做
dequeCell:
。每次我分配新手机时

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = nil
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"abc"];
    return cell;
}
是否可以继续进行此操作,或者是否有更好的替代方法

一些单元格需要从URL下载图像,我使用下面的代码片段

[imgSection setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:column.icon]]]];

请帮助我解决方案

您可以使用唯一的重用标识符来完成

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString* _cellIdentifier = [NSString stringWithFormat:@"RowIdent%ld", (long)indexPath.row];
    TableViewCell* _cell = [tableView dequeueReusableCellWithIdentifier:_cellIdentifier];
    if (!_cell)
    {
        _cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:_cellIdentifier];
    }
    // do awesome
    return _cell;
}
您可以使单元格标识符取决于行号。在这种情况下,重用标识符将正常工作,但所有单元格都是唯一的

更新:

要下载图像,请尝试使用
UIImageView+AFNetworking.h

- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
              placeholderImage:(UIImage *)placeholderImage
                       success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
                       failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
方法()


希望有帮助。

尽管您希望每个单元格都不同,但您不希望每次调用
tableView:cellForRowAtIndexPath:
时都有一个新的单元格-如果用户从某个单元格滚动到另一个单元格,然后再向后滚动,他们仍然会看到相同的单元格。您可以通过正常使用
dequeueReusableCellWithIdentifier:
来实现这一点,但使用
[indepath description]
作为
reuseIdentifier

UDID字符串每次都会生成新的标识符。若我根据索引路径生成标识符,那个么它会更清晰。我用你们的案例更新了我的答案:你们可以使单元格标识符依赖于行数。在这种情况下,重用标识符将正常工作,但您的所有单元格都将是唯一的。是!你是对的。图像下载逻辑应该是alos init方法本身吗?不,你想在不同的线程上下载图像。将它们放入
NSCache
或保存到磁盘,然后在每个下载时,在适当的索引路径重新加载单元格。