2016-02-04 29 views
0

我的tableview,其中每个单元包含标签,图像和按钮。 我的问题是,当我禁用第一个单元格,然后滚动表视图第5单元也禁止UITableView的可重复使用的电池问题迅速

这里是代码

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! DetailTableViewCell 

    cell.preservesSuperviewLayoutMargins = false 
    cell.separatorInset = UIEdgeInsetsZero 
    cell.layoutMargins = UIEdgeInsetsZero 
    print(indexPath.row) 
    if indexPath.row == videoName.count 
    { 

     cell.video_name?.hidden = true 
     cell.artist_name?.hidden = true 
     cell.img?.hidden = true 
     cell.viewer?.hidden = true 
     cell.btn_add?.hidden = true 
     tableView.separatorStyle = UITableViewCellSeparatorStyle.None 

     indicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray) 
     indicator.center = cell.contentView.center 

     if self.pageToken != "" 
     { 
     cell.contentView.addSubview(indicator) 
     indicator.startAnimating() 
     if videoIDArr.count == 25 || videoIDArr.count == 5 
     { 
     if check == 0 
     { 
      loadMoreMostPopularVideo() 
     } 
     else 
     { 
      loadMorePlaylistVideo() 
     } 
     } 
     } 
    } 
    else 
    { 
    indicator.stopAnimating() 

    cell.video_name?.hidden = false 
    cell.artist_name?.hidden = false 
    cell.img?.hidden = false 
    cell.viewer?.hidden = false 
    cell.btn_add?.hidden = false 
    tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine 


    cell.video_name?.text = videoName[indexPath.row] 
    cell.artist_name?.text = artistName[indexPath.row] 

    cell.img?.sd_setImageWithURL(NSURL(string: self.thumbURL[indexPath.row])) 
    cell.viewer?.text = "\(viewerArr[indexPath.row]) views" 
    cell.btn_add.tag = indexPath.row 
    cell.btn_add?.addTarget(self, action: "addVideo:", forControlEvents: UIControlEvents.TouchUpInside) 

    // Disable cell code 
    if dataVideoName.contains(cell.video_name.text!) 
    { 
     cell.img.alpha = 0.50 
     cell.btn_add.alpha = 0.50 
     cell.viewer.alpha = 0.50 
     cell.video_name.alpha = 0.50 
     cell.artist_name.alpha = 0.50 
     cell.userInteractionEnabled = false 
    } 
    } 

    return cell 
} 

enter image description hereenter image description here 我的脸在上午 这个问题给我一些建议解决这个问题

感谢

+0

视频名称是否唯一?此外,我建议你需要为每个对象(视频)添加一个标志,它将声明该单元是启用还是禁用。并为该检查提供一个if条件。 – nikhil84

+0

是的,它是独一无二的 – John

+0

我我的问题 – John

回答

2

你需要使细胞代码如果indexPat h.row == videoName.count {}对称设置单元格的设置


if indexPath.row == videoName.count { 
    .... 

    // Enable cell code 
    if dataVideoName.contains(cell.video_name.text!) 
    { 
     cell.img.alpha = 1 
     cell.btn_add.alpha = 1 
     cell.viewer.alpha = 1 
     cell.video_name.alpha = 1 
     cell.artist_name.alpha = 1 
     cell.userInteractionEnabled = true 
    } 
} else { 
    .... 
    // Disable cell code 
    if dataVideoName.contains(cell.video_name.text!) 
    { 
     cell.img.alpha = 0.50 
     cell.btn_add.alpha = 0.50 
     cell.viewer.alpha = 0.50 
     cell.video_name.alpha = 0.50 
     cell.artist_name.alpha = 0.50 
     cell.userInteractionEnabled = false 
    } 
} 
+0

我不想让细胞 – John

+0

我只检查视频名称在​​数据库中,然后细胞被禁用... – John

+0

我的问题是,当第一个单元格禁用,那么我滚动tableview中那么第五单元也禁用如果有任何解决方案,请重新使用单元 – John