小编man*_*eGE的帖子

Swift 2:UITableViewDataSource协议扩展

我一直在玩协议扩展,我有一个问题.也许我想要实现的目标无法实现.我有这个游乐场:

//: Playground - noun: a place where people can play

import UIKit

protocol ArrayContainer {
    typealias T
    var array: [T] { get }
}

class MyViewController: UIViewController, ArrayContainer, UITableViewDataSource {
    typealias T = String
    var array = ["I am", "an Array"] 
}

extension UITableViewDataSource where Self: ArrayContainer {

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        // …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift2 protocol-extension

5
推荐指数
1
解决办法
2646
查看次数

标签 统计

ios ×1

protocol-extension ×1

swift2 ×1

uitableview ×1