如何使用纯代码swift实现从tableviewcell里面传值到 web view并加载显示
答案:1 悬赏:30 手机版
解决时间 2021-11-19 22:03
- 提问者网友:爱唱彩虹
- 2021-11-19 09:08
如何使用纯代码swift实现从tableviewcell里面传值到 web view并加载显示
最佳答案
- 五星知识达人网友:舊物识亽
- 2021-11-19 10:21
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.
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯