如何使用纯代码swift实现从tableviewcell里面传值到 web view并加载显示
1个回答
2016-03-11 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517201
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
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.
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询