Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Person.swift
- // PersonInformation
- //
- // Created by Sabin Tabirca on 09/02/2024.
- //
- import Foundation
- class Person{
- // class properties
- var name, address, phone, image, url : String
- // class init-s
- init(name: String, address: String, phone: String, image: String, url: String) {
- self.name = name
- self.address = address
- self.phone = phone
- self.image = image
- self.url = url
- }
- init() {
- self.name = "John Doe"
- self.address = "no address"
- self.phone = "no phone"
- self.image = "doe.jpg"
- self.url = "na"
- }
- // class methods
- }
- //
- // People.swift
- // PersonInformation
- //
- // Created by Sabin Tabirca on 09/02/2024.
- //
- import Foundation
- class People{
- var peopleData : [Person]
- init(){
- peopleData =
- [
- Person(name: "Sabin Tabirca", address: "WGB, UCC, Cork", phone: "12345678", image: "sabin.jpeg", url: "http://www.cs.ucc.ie"),
- Person(name: "Sabina Tabirca", address: "CUMH, UCC, Cork", phone: "12345678", image: "sabin.jpeg", url: "http://www.cs.ucc.ie"),
- Person(name: "John Tabirca", address: "Loyds, Cork", phone: "12345678", image: "sabin.jpeg", url: "http://www.cs.ucc.ie"),
- Person(name: "Tany Tabirca", address: "WGB, UCC, Cork", phone: "12345678", image: "sabin.jpeg", url: "http://www.cs.ucc.ie"),
- Person(name: "Sabinus Tabirca", address: "WGB, UCC, Cork", phone: "12345678", image: "sabin.jpeg", url: "http://www.cs.ucc.ie")
- ]
- }
- func getPerson(index:Int)-> Person{
- return peopleData[index]
- }
- func getCount()->Int{
- return peopleData.count
- }
- }
- //
- // PersonViewController.swift
- // PersonInformation
- //
- // Created by Sabin Tabirca on 09/02/2024.
- //
- import UIKit
- class PersonViewController: UIViewController {
- // outlets and actions
- @IBOutlet weak var personImageView: UIImageView!
- @IBOutlet weak var personNameLabel: UILabel!
- // vars and methods
- var personData : Person!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- // fill the label and image view with data
- personNameLabel.text = personData.name
- personImageView.image = UIImage(named: personData.image)
- }
- // MARK: - Navigation
- // 在基于故事板的应用程序中,您通常需要在导航之前做一些准备工作
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- if segue.identifier == "segue1"{
- // 使用 segue.destination 获取新的视图控制器。
- let destination = segue.destination as! DetailsViewController
- // 将选定的对象传递给新的视图控制器。
- destination.personData = self.personData
- }
- }
- }
- //
- // DetailsViewController.swift
- // PersonInformation
- //
- // Created by Sabin Tabirca on 09/02/2024.
- //
- import UIKit
- class DetailsViewController: UIViewController {
- // outlets
- @IBOutlet weak var nameLabel: UILabel!
- @IBOutlet weak var phoneLabel: UILabel!
- @IBOutlet weak var addressLabel: UILabel!
- @IBOutlet weak var imageLabel: UILabel!
- @IBOutlet weak var urlLabel: UILabel!
- // vars and methods
- var personData : Person!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- nameLabel.text = personData.name
- phoneLabel.text = personData.phone
- addressLabel.text = personData.address
- urlLabel.text = personData.url
- imageLabel.text = personData.image
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
- //
- // PeopleTableViewController.swift
- // PersonInformation
- //
- // Created by Sabin Tabirca on 16/02/2024.
- //
- import UIKit
- class PeopleTableViewController: UITableViewController {
- // declare data
- var peopleData : People!
- override func viewDidLoad() {
- super.viewDidLoad()
- // make data
- peopleData = People()
- }
- // MARK: - Table view data source
- override func numberOfSections(in tableView: UITableView) -> Int {
- // #warning Incomplete implementation, return the number of sections#warning 执行不完整,返回节数
- return 1
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- // #warning Incomplete implementation, return the number of rows#warning 执行不完整,返回行数
- return peopleData.getCount()
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
- // Configure the cell...
- let personData = peopleData.getPerson(index: indexPath.row)
- cell.textLabel?.text = personData.name
- cell.detailTextLabel?.text = personData.phone
- cell.imageView?.image = UIImage(named: personData.image)
- return cell
- }
- /*
- // Override to support conditional editing of the table view.覆盖以支持表视图的条件编辑。
- override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
- // Return false if you do not want the specified item to be editable.如果您不希望指定的项目可编辑,则返回 false。
- return true
- }
- */
- /*
- // Override to support editing the table view.覆盖以支持编辑表视图。
- override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
- if editingStyle == .delete {
- // Delete the row from the data source
- tableView.deleteRows(at: [indexPath], with: .fade)
- } else if editingStyle == .insert {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view创建适当类的新实例,将其插入数组,并向表视图添加新行
- }
- }
- */
- /*
- // Override to support rearranging the table view.重写以支持重新排列表视图。
- override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
- }
- */
- /*
- // Override to support conditional rearranging of the table view.重写以支持表视图的条件重新排列。
- override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
- // Return false if you do not want the item to be re-orderable.如果您不希望该商品可重新订购,请返回 false。
- return true
- }
- */
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- if segue.identifier == "segue2"{
- // Get indexPath and data associated with获取indexPath和关联的数据
- let indexPath = tableView.indexPath(for: sender as!UITableViewCell)
- let personData = peopleData.getPerson(index: indexPath!.row)
- // Get the new view controller using segue.destination.使用 segue.destination 获取新的视图控制器。
- let destination = segue.destination as! PersonViewController
- // Pass the selected object to the new view controller.将选定的对象传递给新的视图控制器。
- destination.personData = personData
- }
- }
- }
- //
- // AppDelegate.swift
- // PersonInformation
- //
- // Created by Sabin Tabirca on 09/02/2024.
- //
- import UIKit
- @main
- class AppDelegate: UIResponder, UIApplicationDelegate {
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
- // Override point for customization after application launch.应用程序启动后自定义的覆盖点。
- return true
- }
- // MARK: UISceneSession Lifecycle
- func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
- // Called when a new scene session is being created.创建新场景会话时调用。
- // Use this method to select a configuration to create the new scene with.使用此方法选择用于创建新场景的配置。
- return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
- }
- func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
- }
- }
- //
- // SceneDelegate.swift
- // PersonInformation
- //
- // Created by Sabin Tabirca on 09/02/2024.
- //
- import UIKit
- class SceneDelegate: UIResponder, UIWindowSceneDelegate {
- var window: UIWindow?
- func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
- guard let _ = (scene as? UIWindowScene) else { return }
- }
- func sceneDidDisconnect(_ scene: UIScene) {
- }
- func sceneDidBecomeActive(_ scene: UIScene) {
- }
- func sceneWillResignActive(_ scene: UIScene) {
- }
- func sceneWillEnterForeground(_ scene: UIScene) {
- }
- func sceneDidEnterBackground(_ scene: UIScene) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement