swift tableviewcontroller自定义列表

  1 //
  2 //  JieTableViewController.swift
  3 //  JieTableView
  4 //
  5 //  Created by jiezhang on 14-10-5.
  6 //  Copyright (c) 2014年 jiezhang. All rights reserved.
  7 //
  8
  9 import UIKit
 10
 11 class JieTableViewController: UITableViewController {
 12
 13     var listVideos : NSMutableArray!
 14
 15     override func viewDidLoad() {
 16         super.viewDidLoad()
 17         var bundle = NSBundle.mainBundle()
 18         let plistPath : String! = bundle.pathForResource("videos", ofType: "plist")
 19         listVideos = NSMutableArray(contentsOfFile: plistPath)
 20         // Uncomment the following line to preserve selection between presentations
 21         // self.clearsSelectionOnViewWillAppear = false
 22
 23         // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
 24         //下面这段话是设置左边编辑,右边添加item
 25
 26         self.navigationItem.leftBarButtonItem = self.editButtonItem()
 27         let addButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "insertNewObject:")
 28         self.navigationItem.rightBarButtonItem = addButton
 29
 30     }
 31
 32     func insertNewObject(sender: AnyObject) {
 33         var item : NSDictionary = NSDictionary(objects:["http://c.hiphotos.baidu.com/video/pic/item/f703738da977391224eade15fb198618377ae2f2.jpg","新增数据", NSDate.date().description] , forKeys: ["video_img","video_title","video_subTitle"])
 34         listVideos.insertObject(item, atIndex: 0)
 35         let indexPath = NSIndexPath(forRow: 0, inSection: 0)
 36         self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
 37     }
 38
 39
 40     override func didReceiveMemoryWarning() {
 41         super.didReceiveMemoryWarning()
 42         // Dispose of any resources that can be recreated.
 43     }
 44
 45     // MARK: - Table view data source
 46     //返回节的个数
 47     override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
 48         // #warning Potentially incomplete method implementation.
 49         // Return the number of sections.
 50         return 1
 51     }
 52     //返回某个节中的行数
 53     override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 54         // #warning Incomplete method implementation.
 55         // Return the number of rows in the section.
 56         return listVideos.count
 57     }
 58     //为表视图单元格提供数据,该方法是必须实现的方法
 59     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
 60         let cellIdentifier : String = "videoItem"
 61         let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as JieTableViewCell
 62         var row = indexPath.row
 63         var rowDict : NSDictionary = listVideos.objectAtIndex(row) as NSDictionary
 64         let url : String = rowDict.objectForKey("video_img") as String
 65         let dataImg : NSData = NSData(contentsOfURL: NSURL(string : url))
 66         cell.JieVideoImg.image = UIImage(data: dataImg)
 67         cell.JieVideoTitle.text = rowDict.objectForKey("video_title") as? String
 68         cell.JieVideoSubTitle.text = rowDict.objectForKey("video_subTitle") as? String
 69         return cell
 70
 71     }
 72
 73     override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
 74
 75     }
 76
 77     // 支持单元格编辑功能
 78     override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
 79         // Return NO if you do not want the specified item to be editable.
 80         return true
 81     }
 82
 83     // Override to support editing the table view.
 84     override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
 85         if editingStyle == .Delete {
 86             // Delete the row from the data source
 87             listVideos.removeObjectAtIndex(indexPath.row)
 88             tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
 89         } else if editingStyle == .Insert {
 90             // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 91         }
 92     }
 93
 94
 95     // Override to support rearranging the table view.
 96     override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
 97         if fromIndexPath != toIndexPath{
 98             var object: AnyObject = listVideos.objectAtIndex(fromIndexPath.row)
 99             listVideos.removeObjectAtIndex(fromIndexPath.row)
100             if toIndexPath.row > self.listVideos.count{
101                 self.listVideos.addObject(object)
102             }else{
103                 self.listVideos.insertObject(object, atIndex: toIndexPath.row)
104             }
105         }
106     }
107
108
109
110     // Override to support conditional rearranging of the table view.
111     //在编辑状态,可以拖动设置item位置
112     override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
113         // Return NO if you do not want the item to be re-orderable.
114         return true
115     }
116
117
118
119     // MARK: - Navigation
120
121     //给新进入的界面进行传值
122     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
123         if segue.identifier == "showDetail" {
124             if let indexPath = self.tableView.indexPathForSelectedRow() {
125                 let object : NSDictionary = listVideos[indexPath.row] as NSDictionary
126                 (segue.destinationViewController as JieDetailViewController).detailItem = object
127             }
128         }
129     }
130
131
132
133
134 }
时间: 2024-08-08 03:51:54

swift tableviewcontroller自定义列表的相关文章

Swift基础--使用TableViewController自定义列表

首先建立一个swift项目,把storyboard的内容删掉,添加一个Navigation Controller,然后设置storyboard对应界面的class,在Navigation Controller界面设置View Controller的is initial View Controller,这里使用的自定义列表内容,所以要新建一个继承UITableViewCell的类,然后设置storyboard中Table View的Prototype Cells的class,对于点击item进入详

[安卓] 16、ListView和GridView结合显示单元实现自定义列表显示效果

List在各种手机应用中都有体现,是安卓UI设计的必修课. 本文将介绍在开发中如何利用ListView和GridView设计自定义列表. 下面分别是用ListView和GridView做的效果: 上面两个看似相差很大,但是其代码非常类似,主要有:     ① 在页面中嵌入ListView或GridView: ListView的activity_main.xml 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/r

sharepoint 2016 学习系列篇(13)-自定义列表应用篇-(2)添加字段栏

前面创建完列表之后,我们需要在用户信息表中,添加一些我们需要用到的字段,当然还可以添加更多的字段,这里我们只是简单做一个示例,介绍如何在自定义列表(Custom List)中创建字段栏. 我们先创建一个字段"姓名". 打开我们前面创建好的用户信息表,点击列表的空白位置,在左上角会显示出一些标签的按钮,点击"列表(List)"标签,点击列表设置(List Settings), 进入设置页面,在下方找到栏(Column),点击创建栏(Create column), 进入

sharepoint2010 创建自定义列表

sharepoint2010 创建自定义列表 分类: sharepoint20102014-04-04 14:06 106人阅读 评论(0) 收藏 举报 转:http://boke.25k5.com/kan77298.html 如何创建自定义列表 首先了解创建自定义列表中涉及到的几个名词:栏.内容类型. ①栏:栏即列.字段(Field),MSDN中给出的解释为:“字段”一词在 SharePoint Foundation 开发中有两个关系非常密切的含义.有时它指的是列表中的列,但如果提到单个列表项

帝国cms7.2自定义列表建立tag效果 代码 教程

统计记录:(如:select count(*) as total from phome_ecms_news where classid=1 and checked=1) 注:这句SQL的意思是查找统计位于数据表phome_ecms_news 新闻数据表的栏目id=1和审核过的信息总数 在我们平时用的栏目模板里面  就是 本栏目一共有xxx条信息.   xxx就是用这个SQL统计出来的. 查询记录:(如:select * from phome_ecms_news where classid=1 a

sharepoint 2013 自定义列表查看页面附件打开新页面方法 dispform attachments open new page

我们在sharepoint的列表中,打开某一条数据,如果那条数据有附件,打开附件的时候,总是会把当前的页面给替换掉.如何在点击附件的时候,打开新页面,可以用一下一段脚本来处理. <script> $(document).ready(function () { if ($("#idAttachmentsTable") != null) { $('#idAttachmentsTabletbody tr td').each(function () { var href = $(t

HTML学习之有序列表、无序列表和自定义列表

列表分成三种类型:有序列表.无序列表和自定义列表. 有序列表使用编号来记录项目的顺序 无序列表使用项目符号来记录无序的项目 自定义列表它由两个部分组成:定义条件和定义描述. 有序列表: <OL  type="编号样式" start="编号起始值"> <LI>项目一</LI> <LI>项目二</LI> .... </OL> type 1 阿拉伯数字 a英文小写 A英文大写 i罗马小写数字 I罗马大

每日学习心得:SharePoint 2013 自定义列表项添加Callout菜单项、文档关注、SharePoint服务端对象模型查询

前言: 前一段时间一直都比较忙,没有什么时间进行总结,刚好节前项目上线,同时趁着放假可以好好的对之前遇到的一些问题进行总结.主要内容有使用SharePoint服务端对象模型进行查询.为SharePoint 自定义列表项添加callout菜单.希望能够给大家带来一些帮助. 1.  在aspx页引用可视化Web部件 有时候会需要在页面中引用项目中创建的可视化Web部件,具体步骤有以下这几步: 1) 在aspx页面顶部注册该可视化Web部件 示例如下: <%@ Register Tagprefix=&qu

sharepoint 2016 学习系列篇(15)-自定义列表应用篇-(4)数据权限配置

当数据已经录入到列表中之后,接下来,朋友们可能会想知道,有些数据,只想给某些用户看到,或者编辑,列表是否支持这样的操作. 大微软的sharepoint平台,对于用户的需求,可以说是考虑得很周全的,权限管理,当然也是不可能漏掉的,而且权限管理,还是sharepoint上一个非常突出的亮点,数据安全性管理的颗粒度,很完善.接下来,我们来看下,如何在sharepoint的自定义列表中,给数据配置不同的用户访问权限,这些当然也是不需要开发,就能实现的. 前面讲到,用户访问sharepoint平台网站的时