import UIKit class MyTable: UITableViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
import UIKit class MyTable: UITableViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { //- return 10 } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // n- let cell = tableView.dequeueReusableCellWithIdentifier("MyCell") as UITableViewCell cell.textLabel.text = " #\(indexPath.item)" return cell } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { // - } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { // - ( 1) return 1 } }
import UIKit class Detail: UIViewController { required init(coder aDecoder: NSCoder) { id = 0 super.init(coder: aDecoder) } @IBOutlet weak var idDetail: UILabel!// "id..." // , , var id: Int // id view override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. idDetail.text = "\(id)" } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {// Detail let vc = segue.destinationViewController as Detail let id = sender as Int// Detail vc.id = id } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { // - performSegueWithIdentifier("ToDetail", sender: indexPath.item)// , }
import UIKit class MyTable: UITableViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { //- return 10 } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // n- let cell = tableView.dequeueReusableCellWithIdentifier("MyCell") as UITableViewCell cell.textLabel.text = " #\(indexPath.item)" return cell } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {// Detail let vc = segue.destinationViewController as Detail let id = sender as Int// Detail vc.id = id } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { // - performSegueWithIdentifier("ToDetail", sender: indexPath.item)// ? } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { // - ( 1) return 1 } }
func doIt() { // - id println(id) // navigationController?.popViewControllerAnimated(true) }
var rightButton = UIBarButtonItem(title: "", style: .Done, target: self, action: "doIt") self.navigationItem.rightBarButtonItem = rightButton
import UIKit class Detail: UIViewController { required init(coder aDecoder: NSCoder) { id = 0 super.init(coder: aDecoder) } @IBOutlet weak var idDetail: UILabel!// , id var id: Int// , vc id override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. idDetail.text = "\(id)" var rightButton = UIBarButtonItem(title: "", style: .Done, target: self, action: "doIt") self.navigationItem.rightBarButtonItem = rightButton } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func buyPressed(sender: AnyObject) { doIt() } func doIt() { // - id println(id) // navigationController?.popViewControllerAnimated(true) } }
Source: https://habr.com/ru/post/244655/
All Articles