gpt4 book ai didi

ios - 如何解决错误“viewController 对 swift 协议(protocol) UIScrollViewDelegate 的冗余一致性?

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:32 24 4
gpt4 key购买 nike

我是 stackOverflow 的新手,正在快速学习。我收到错误 “在使用 Stretch headers.UIScrollViewDelegate 时,viewController 对协议(protocol)的冗余一致性。我在下面指定我的代码。请更正任何一个。

class ViewController: UITableViewController , UIScrollViewDelegate {
private let kTableHeaderHeight : CGFloat = 300.0
// Using Implicitly Unwrapped Optional, UIView!
var headerView:UIView!

let items = [
NewsItem(category: .World, summary: "Climate Change protests, Need to preserve our Ecosysytem"),
NewsItem(category: .India, summary: "Climate Change protests, Need to preserve our Ecosysytem"),
NewsItem(category: .America, summary: "Climate Change protests,Need to preserve our Ecosysytem"),
NewsItem(category: .Japan, summary: "Climate Change protests, Need to preserve our Ecosysytem"),
NewsItem(category: .China, summary: "Climate Change protests, Need to preserve our Ecosysytem"),
NewsItem(category: .Nepal, summary: "Climate Change protests, Need to preserve our Ecosysytem")]
override func viewDidLoad() {
super.viewDidLoad()
headerView = tableView.tableHeaderView
tableView.tableHeaderView = nil
tableView.addSubview(headerView)
tableView.contentInset = UIEdgeInsetsMake(kTableHeaderHeight, 0, 0, 0)
tableView.contentOffset = CGPointMake(0, -kTableHeaderHeight)
updateHeaderView()
}
func updateHeaderView(){
var HeaderRect = CGRectMake(0,-kTableHeaderHeight, tableView.bounds.width, kTableHeaderHeight)

if tableView.contentOffset.y < -kTableHeaderHeight{
HeaderRect.origin.y = tableView.contentOffset.y
HeaderRect.size.height = -tableView.contentOffset.y
}
headerView.frame = HeaderRect
}
override func didReceiveMemoryWarning() {enter code here
super.didReceiveMemoryWarning()
}
override func scrollViewDidScroll(scrollView: UIScrollView) {
updateHeaderView()
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let item = items[indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier("Cell" forIndexPath: indexPath) as! NewsItemTableViewCell
cell.newsItem = item
return cell
}

最佳答案

您收到此错误是因为您的类 ViewController 以两种方式符合协议(protocol) UIScrollViewDelegateUITableViewController 已经符合该协议(protocol),您无需再次添加它。所以从那里删除 UIScrollViewDelegate,你很好。

这就是 UITableViewController 符合 UITableViewDelegate 而符合 UIScrollViewDelegate 的方式。这样就够了

class ViewController: UITableViewController{
}

关于ios - 如何解决错误“viewController 对 swift 协议(protocol) UIScrollViewDelegate 的冗余一致性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37896298/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com