我是stackOverflow的新手,学习敏捷。我收到错误
“在使用Stretch header .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符合UITableViewDelegateUIScrollViewDelegate的方式。这样就足够了

class ViewController: UITableViewController{
}

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

10-11 19:49