2016-06-18 40 views
3

我是新的stackOverflow和学习迅速。我得到错误 ”冗余一致性viewController协议处理Stretch headers.UIScrollViewDelegate。我在下面指定我的代码。请纠正任何一个。如何解决错误“冗余一致性viewController协议UIScrollViewDelegate在swift?

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   
    } 

回答

8

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

这就是UITableViewController是如何符合UITableViewDelegate,它符合UIScrollViewDelegate。这将是足够的

class ViewController: UITableViewController{ 
} 
+0

非常感谢您 – Harish

+0

也为我工作过!谢谢,顺便说一句,这也是在firebase示例代码[这里](https://github.com/firebase/quickstart-android/tree/master/messaging) –

2

最短的解释是你的UITableViewController带有一个内置的滚动视图,所以你需要滚动型的委托。删除UIScrollViewDelegate,你会没事的。

随意问任何问题:)