import UIKit
class MainViewController:UIViewController,UITableViewDataSource,UITableViewDelegate{
var tableView = UITableView()
overridefunc viewDidLoad() {
super.viewDidLoad()
self.title="我的"
let rightItem = UIBarButtonItem.init(title:"登陆", style: .done, target:self, action: #selector(rightItemClick))
self.navigationItem.rightBarButtonItem=rightItem
tableView = UITableView.init(frame: CGRect(x:0, y: 0, width:self.view.bounds.size.width, height:600), style: .plain)
tableView.delegate=self
tableView.dataSource=self
self.view.addSubview(tableView)
}
func numberOfSectionsInTableView(tableView:UITableView) -> Int {
return1
}
func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
return10
}
func tableView(_ tableView:UITableView, heightForRowAt indexPath:IndexPath) -> CGFloat {
return60
}
func tableView(_ tableView:UITableView, cellForRowAt indexPath:IndexPath) -> UITableViewCell {
let cellid="cellid"
var cell=tableView.dequeueReusableCell(withIdentifier: cellid)
if cell==nil
{
cell=UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: cellid)
}
cell!.textLabel?.text="1234"
return cell!
}
func tableView(_ tableView:UITableView, didSelectRowAt indexPath:IndexPath) {
print(indexPath.row)
}
func rightItemClick() {
let login = LoginViewController()
let nav = UINavigationController.init(rootViewController: login)
self.present(nav, animated:true, completion: nil)
}
}