o halde verdiğim örnekte DetailViewController.swift içerisindeki tüm kodları, aşağıda verdiğim kodlarla değiştirirseniz istediğiniz sonuca ulaşabilirsiniz.
import UIKit
class DetailViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var selectedPersonalData:Dictionary<String,AnyObject>! = nil
var tableView:UITableView! = nil
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.greenColor()
self.title = "personel detayı"
self.tableView = UITableView(frame: self.view.frame)
self.tableView.backgroundColor = UIColor.clearColor()
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
self.tableView.separatorInset = UIEdgeInsetsZero
self.tableView.allowsMultipleSelection = false
self.tableView.allowsMultipleSelectionDuringEditing = false
self.tableView.allowsSelectionDuringEditing = false
self.tableView.allowsSelection = false
self.view.addSubview(self.tableView)
}
override func viewDidDisappear(animated: Bool) {
self.selectedPersonalData = nil
self.tableView.reloadData()
}
override func viewWillAppear(animated: Bool) {
self.tableView.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.selectedPersonalData != nil {
return self.selectedPersonalData.count
} else {
return 0
}
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var Identifier:String = "cellid"
var myCell:UITableViewCell! = nil
if var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(Identifier) as? UITableViewCell {
myCell = cell
} else {
myCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: Identifier)
}
var rowLabel:String = ""
switch indexPath.row {
case 0:
if let id:Int = self.selectedPersonalData["id"] as? Int {
rowLabel = String(format: "personel no: %i", id)
}
case 1:
if let name:String = self.selectedPersonalData["name"] as? String {
rowLabel = String(format: "adı: %@", name)
}
case 2:
if let lastname:String = self.selectedPersonalData["lastname"] as? String {
rowLabel = String(format: "soyadı: %@", lastname)
}
case 3:
if let birthday:String = self.selectedPersonalData["birthday"] as? String {
rowLabel = String(format: "doğum yılı: %@", birthday)
}
default:
break
}
myCell.textLabel?.textColor = UIColor.blackColor()
myCell.textLabel?.font = UIFont(name: "Arial", size: myCell.frame.size.height * 0.4)
myCell.textLabel?.text = rowLabel
return myCell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}