小编I'm*_*ama的帖子

如何在Swift中将数据从一个表视图传递到另一个表视图?

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var tableView: UITableView
    var dict1:Dictionary<Int,String> = [ 0:"One",1:"TwO",2:"Three"];

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }


    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
        return self.dict1.count;
    }

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

        cell.textLabel.text = self.dict1[indexPath.row]

        return cell
    }

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        println("You selected cell #\(indexPath.row)!")

    }               
}
Run Code Online (Sandbox Code Playgroud)

uitableview uinavigationcontroller ios swift

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

标签 统计

ios ×1

swift ×1

uinavigationcontroller ×1

uitableview ×1