【发布时间】:2016-05-13 18:34:57
【问题描述】:
我有一个表格视图,其中每个单元格都包含标签、图像和按钮。 我的问题是当我禁用第一个单元格和滚动表视图第 5 个单元格时也禁用
这里是代码
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
}
谢谢
【问题讨论】:
-
视频名称是否唯一?另外我建议您需要为每个对象(视频)添加一个标志,该标志将说明单元格是启用还是禁用。并为该检查设置一个 if 条件。
-
我还添加了我的问题的屏幕截图
-
所以我建议将该标志添加到您的对象(视频)中,这样您就可以在检查该标志时启用或禁用单元格。
-
感谢您的建议问题已解决
标签: objective-c swift uitableview