[英]how to make limited multiple checkmark in Table View Cell in Swift?
[英]How to make a click on cell of a Table View in Swift
这是我使用很棒的SWIFT语言的第一天,我试图用一些数据填充表格视图,一切似乎都正常,但是我想让表格视图可点击并打印所点击项目的ID,但是似乎没有工作,我没有收到任何错误消息。
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var categories = [Category]()
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return categories.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = categories[indexPath.row].Label
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("You selected cell #\(indexPath.row)!")
}
override func viewDidLoad() {
super.viewDidLoad()
let reposURL = NSURL(string: "http://myserver.com/file.json")
// 2
if let JSONData = NSData(contentsOfURL: reposURL!) {
// 3
if let json = NSJSONSerialization.JSONObjectWithData(JSONData, options: nil, error: nil) as? NSDictionary {
// 4
if let reposArray = json["List"] as? [NSDictionary] {
// 5
for item in reposArray {
categories.append(Category(json: item))
}
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.