swift纯代码,如何实现点击某行cell,将它的内容反映到前一个页面的输入框。
展开全部
RT Swift 读取plist文件 加载到Table View上
class ENTableViewController: UITableViewController {
var listVidos:NSMutableArray!
override func viewDidLoad() {
super.viewDidLoad()
//创建bundle
var ban = NSBundle.mainBundle()
//读取plist文件路径
let plistpath = ban.pathForResource("tgs", ofType: "plist")!
//读取plist内容放到NSMutableArray内
listVidos = NSMutableArray(contentsOfFile: plistpath)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//tableView 显示多少组
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
//tableView 每个组显示多少行数据
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return listVidos.count
}
//每个cell的数据
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
println("进来了tableView")
//名字和identifiler名字一样
let cellIdentifier : String = "videoItem"
//加载cell
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as ENTableViewCell
//获取行
var row = indexPath.row
var rowDict : NSDictionary = listVidos.objectAtIndex(row) as NSDictionary
cell.lab.text = rowDict.objectForKey("title") as? String
return cell
}
}
注:Table View的identifiler界面
另点击cell传值加入如下方法
//点击cell跳转
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "abc" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let object : NSDictionary = listVidos[indexPath.row] as NSDictionary
(segue.destinationViewController as ENViewController).detailItem = object
}
}
}
ENViewController为被跳转的界面
其中abc值为
第二个界面
import UIKit
class ENViewController: UIViewController {
//第二个界面
@IBOutlet weak var lla: UILabel!
var detailItem:NSDictionary?
override func viewDidLoad() {
super.viewDidLoad()
configureView()
// Do any additional setup after loading the view.
}
func configureView() {
if let detail : NSDictionary = self.detailItem {
self.lla.text = detail.objectForKey("title") as? String
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class ENTableViewController: UITableViewController {
var listVidos:NSMutableArray!
override func viewDidLoad() {
super.viewDidLoad()
//创建bundle
var ban = NSBundle.mainBundle()
//读取plist文件路径
let plistpath = ban.pathForResource("tgs", ofType: "plist")!
//读取plist内容放到NSMutableArray内
listVidos = NSMutableArray(contentsOfFile: plistpath)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//tableView 显示多少组
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
//tableView 每个组显示多少行数据
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return listVidos.count
}
//每个cell的数据
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
println("进来了tableView")
//名字和identifiler名字一样
let cellIdentifier : String = "videoItem"
//加载cell
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as ENTableViewCell
//获取行
var row = indexPath.row
var rowDict : NSDictionary = listVidos.objectAtIndex(row) as NSDictionary
cell.lab.text = rowDict.objectForKey("title") as? String
return cell
}
}
注:Table View的identifiler界面
另点击cell传值加入如下方法
//点击cell跳转
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "abc" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let object : NSDictionary = listVidos[indexPath.row] as NSDictionary
(segue.destinationViewController as ENViewController).detailItem = object
}
}
}
ENViewController为被跳转的界面
其中abc值为
第二个界面
import UIKit
class ENViewController: UIViewController {
//第二个界面
@IBOutlet weak var lla: UILabel!
var detailItem:NSDictionary?
override func viewDidLoad() {
super.viewDidLoad()
configureView()
// Do any additional setup after loading the view.
}
func configureView() {
if let detail : NSDictionary = self.detailItem {
self.lla.text = detail.objectForKey("title") as? String
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询