swift读取plist文件内容用UITableView展示
来源:互联网 发布:java不兼容的类型 编辑:程序博客网 时间:2024/05/16 14:56
plist内容如图
viewController.swift
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { var cells : NSDictionary? // Global Variable override func viewDidLoad() { super.viewDidLoad() let path = NSBundle.mainBundle().bundlePath let plistName:NSString = "Property List.plist" let finalPath:NSString = (path as NSString).stringByAppendingPathComponent(plistName as String) cells = NSDictionary(contentsOfFile:finalPath as String) } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return cells!.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell { let cell:CustomCell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as! CustomCell let myCell: AnyObject = cells!.objectForKey("cell\(indexPath.row)") as! NSDictionary cell.myTitle?.text = myCell.objectForKey("title") as? String cell.mySubtitle?.text = myCell.objectForKey("subtitle") as? String cell.myImage?.image = UIImage(named: myCell.objectForKey("image") as! String) return cell } func tableView(tableView: UITableView, titleForHeaderInSection section:Int) -> String? { return "TuxMania" } func tableView(tableView: UITableView, titleForFooterInSection section:Int) -> String? { return "Get all the Tux" } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
customCell.swift
class CustomCell: UITableViewCell { @IBOutlet weak var myImage: UIImageView! @IBOutlet weak var myTitle: UILabel! @IBOutlet weak var mySubtitle: UILabel! override func awakeFromNib() { super.awakeFromNib() } override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } }
运行结果
0 0
- swift读取plist文件内容用UITableView展示
- iOS 读取plist文件内容
- swift读取本地数据元 *.plist 文件
- IOS中plist文件内容的读取
- iOS从plist文件里面读取内容
- plist文件的内容的读取
- UITableVIew读取plist文件及删除对象的操作
- UITableView, .plist文件
- Swift - .plist文件数据的读取和存储
- Swift plist文件读写
- swift plist文件
- ios中读取plist文件内容的方法
- ios本地文件内容读取,.json .plist 文件读写
- 读取plist文件
- IOS读取.plist文件
- NSArray 读取plist文件
- 读取plist文件
- OC读取plist文件
- HDU 1165 Eddy's research II
- ASIHTTPRequest的使用——队列请求
- Python解析文件中的unicode字符
- 关于ucgui多应用调度框架解析
- java数据库基本操作
- swift读取plist文件内容用UITableView展示
- 简易php博客(6)_后台修改
- Java自定义注解的实现
- LeetCode:String to Integer (atoi)
- Activity
- 0-时间复杂度&空间复杂度的计算
- BZOJ 3110 [Zjoi2013]K大数查询
- Latex 入门
- 在QWidget 窗口上弹出右键菜单