Iphone 如果第一次填充单元格,如何限制tableview第二次填充单元格

Iphone 如果第一次填充单元格,如何限制tableview第二次填充单元格,iphone,ios,objective-c,uitableview,Iphone,Ios,Objective C,Uitableview,在我的TableView中,我设置了图像和两个标签,填充效果很好。但当我向下滚动TableView,然后重新查看已填充的单元格时,它将重新填充。现在我用来自URL的图像填充ImageView,这样它将为我的用户创建负载 因此,我可以限制我的TableView,如果我的单元格第一次被填充,它将不会再次填充 这是我的代码: - (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPa

在我的TableView中,我设置了图像和两个标签,填充效果很好。但当我向下滚动TableView,然后重新查看已填充的单元格时,它将重新填充。现在我用来自URL的图像填充ImageView,这样它将为我的用户创建负载

因此,我可以限制我的TableView,如果我的单元格第一次被填充,它将不会再次填充

这是我的代码:

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

    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

    UITableViewCell * cell = [atableView  dequeueReusableCellWithIdentifier: nil];

    if(cell == nil) {

        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:SimpleTableIdentifier];

        ChannelList *channelList = nil;
        if (searchedData.count ==0) {
            channelList = [channelAllData objectAtIndex:[indexPath section]];
        } else {
            channelList = [searchedData objectAtIndex:[indexPath section]];
        }


        UIImageView *aImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 50, 50)];
        aImageView.image = [UIImage imageNamed:@"tv-defolt.png"];
        NSString * mystr = [channelList channelLogo];

        if (mystr.length !=0) {
            //get a dispatch queue
            dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            //this will start the image loading in bg
            dispatch_async(concurrentQueue, ^{
                NSString * str = [NSString stringWithFormat:@"http://manektech.net/mttv/Channel/%@",[channelList channelLogo]];
                NSData *image = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:str]];

                //this will set the image when loading is finished
                dispatch_async(dispatch_get_main_queue(), ^{
                    aImageView.image = [UIImage imageWithData:image];
                });
            });
        } else {
            aImageView.image = [UIImage imageNamed:@"tv-defolt.png"];
        }

        [cell addSubview:aImageView];


        UILabel *nameTextLabel =  [[UILabel alloc] initWithFrame: CGRectMake(80, 15, 175, 20)];
        nameTextLabel.textColor = [UIColor blackColor];
        nameTextLabel.backgroundColor = [UIColor clearColor];
        nameTextLabel.text = [channelList channelName];
        nameTextLabel.font = [UIFont fontWithName:@"Arial" size:14];
        [cell addSubview:nameTextLabel];

        UILabel *genreTextLabel =  [[UILabel alloc] initWithFrame: CGRectMake(80, 35, 175, 20)];
        genreTextLabel.textColor = [UIColor grayColor];
        genreTextLabel.backgroundColor = [UIColor clearColor];

        NSString * str = [NSString stringWithFormat:@"%@ | %@",[channelList channelType],[channelList channelCounry]];

        genreTextLabel.text = str;
        genreTextLabel.font = [UIFont fontWithName:@"Arial" size:14];
        [cell addSubview:genreTextLabel];


    cell.selectionStyle = UITableViewCellSelectionStyleGray;


    }
    return cell;

}
您应该使用以避免惰性表滚动。 它使用缓存,避免每次都请求图像URL。

您应该使用它来避免惰性表格滚动。
它使用缓存,避免每次都请求图像URL。

试试这个逻辑,可能会对你有用

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

     NSString *SimpleTableIdentifier = [NSString stringWithFormat:@"Cell%d%d",indexPath.section,indexPath.row]; /// set different idenfifier for all cell

    UITableViewCell * cell = [atableView  dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:SimpleTableIdentifier] autorelease];
        /// Add UIImageView and UILable here 
    }    
}

我希望这对你有帮助……

试试这个逻辑,也许它会对你有用

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

     NSString *SimpleTableIdentifier = [NSString stringWithFormat:@"Cell%d%d",indexPath.section,indexPath.row]; /// set different idenfifier for all cell

    UITableViewCell * cell = [atableView  dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:SimpleTableIdentifier] autorelease];
        /// Add UIImageView and UILable here 
    }    
}

我希望这对您有所帮助……

将您的
UILabel
UIImageview
放在中间

if(cell == nil) 
{
    cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault

  .
  .
  .

    // create `UILabel` and `UIImageview`  here add add it to cell.contentView
}

cell.contentView
Crete您的
UILabel
UIImageview
之间

if(cell == nil) 
{
    cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault

  .
  .
  .

    // create `UILabel` and `UIImageview`  here add add it to cell.contentView
}

单元格中都有。contentView

使用SDWebImage而不是lazy table会更好。尝试一下,这对于在后台下载图像并存储在我们的目录中的AsynImage很有用,但这是仅第一次加载该单元格的逻辑,而不是单元格loaded@PingDanehog看看你的问题是什么,你的问题是我第一次问的,所以我发布了这个答案…是的,你的答案是helpfull+1。但我认为这是一个选择,如果SDWebImage可以帮助我减少应用程序下载量,或者我使用的方法更好。回答不错,我已经检查过了,我的手机会使用log第二次调用imageurl。但事实并非如此。所以它不会使用额外的网络下载。这对我来说更好。使用SDWebImage而不是lazy table是否更好。试试看,这对于在后台下载图像并存储在我们的目录中的AsynImage很有用,但这是只在第一次加载该单元格时才加载的逻辑,该单元格不是loaded@PingDanehog看看你的问题是什么,你的问题是我第一次问的,所以我发布了这个答案…是的,你的答案是helpfull+1。但我认为这是一个选择,如果SDWebImage可以帮助我减少应用程序下载量,或者我使用的方法更好。回答不错,我已经检查过了,我的手机会使用log第二次调用imageurl。但事实并非如此。所以它不会使用额外的网络下载。这对我来说更好。使用SDWebImage而不是lazy表是否更好。使用SDWebImage而不是lazy表是否更好。