2017-01-22 5 views
0

스위프트 3의 tvOS 프로젝트에서 내 tableview에 대한이 코드를 가지고 있습니다. 스크롤하지 않으면 색상 셀이 필요합니다! 어떻게 설명 할 수 있니? 당신의 tableview 위임에스크롤 셀을 uitable에 넣을 때 초점 및 색상 변경

이 내 코드

func numberOfSections(in tableView: UITableView) -> Int { 
 
    return 1 
 
} 
 
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
 
    return tvChannelsArray.count 
 
} 
 
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) 
 
    
 
    // Show TV Channels names 
 
    cell.textLabel?.text = ((tvChannelsArray[(indexPath as NSIndexPath).row] as AnyObject).object(forKey: "channel") as! String) 
 
    
 
    cell.imageView?.image = UIImage(named: "\(cell.textLabel!.text!)") 
 
    
 
return cell 
 
} 
 
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
 
    channelsTableView.isHidden = false; 
 

 
    return 100 
 
    
 
}

답변

0

는 UISsrollViewDelegate 방법 ScrollViewDidScroll

func scrollViewDidScroll(_ scrollView: UIScrollView) { 
     for cell in tableView.visibleCells { 
      if let currentCellPath = tableView.indexPath(for: cell), 
       let selectedCellPath = tableView.indexPathForSelectedRow { 
       guard currentCellPath != selectedCellPath else { 
        continue 
       } 
      } 
      let red = Float(cell.frame.origin.y/scrollView.contentSize.height) 
      cell.contentView.backgroundColor = UIColor(colorLiteralRed: red, green: 0.5, blue: 0.25, alpha: 1) 
     } 
    } 
+0

있는 tableView 그것을 변경하는 방법을 찾을 수없는 말 구현할? – user1178728