【发布时间】:2016-05-23 07:52:00
【问题描述】:
我的目标是做一个分组的tableView,但不知何故数据没有添加到tableView中
这是故事板图片
我写的代码好像不行
import UIKit
import Alamofire
import SwiftyJSON
import KeychainAccess
class SettingsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
let keychain = Keychain(server: "https://genietesting.herokuapp.com", protocolType: .HTTPS)
var profile: [String]?
let aboutGenie = [
"How it works",
"About",
"Contact"
]
override func viewDidLoad() {
super.viewDidLoad()
let firstName = keychain[string: "first_name"]
profile = [
firstName!
]
tableView.dataSource = self
tableView.delegate = self
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return profile!.count
} else {
return aboutGenie.count
}
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Profile"
} else {
return "About Genie"
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let tableCell = tableView.dequeueReusableCellWithIdentifier("myCell")
return tableCell!
}
}
当然,我想让它成为可点击的,这样它就可以转到自己的 viewController
经过一些建议,我更改了上面的大部分代码,结果还是一样,但这次它显示了标题
结果是
【问题讨论】:
-
你有没有连接数据源和表视图的委托方法到视图控制器的响应者??
-
很抱歉问这个问题,我该怎么做?
-
请查看此链接。 stackoverflow.com/questions/11265039/… 很简单。 yourTableViewName.delegate = self; yourTableViewName.datasource = self;
标签: ios swift uitableview