当前位置: 首页 > news >正文

济南网站建设0531sosowordpress 自动推荐

济南网站建设0531soso,wordpress 自动推荐,新闻资讯网站怎么做,哪个网站做员工增员在iOS的开发过程中#xff0c;tableView的使用永远都是最常用的控件。今天学习了一下tableViewCell的操作。代码并不是很复杂#xff0c;如果有OC开发经验的人#xff0c;应该很容易看懂的。 class ViewController: UIViewController ,UITableViewDelegate, UITableViewData…在iOS的开发过程中tableView的使用永远都是最常用的控件。今天学习了一下tableViewCell的操作。代码并不是很复杂如果有OC开发经验的人应该很容易看懂的。 class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource { // 因为Swift中要求变量或常量在声明时就要初始化其值所以我们在实际开发中声明变量或常量时使用可选类型。后面代码中使用到以上变量时需要加 ! 对其解包。var tableView : UITableView? // var items :NSMutableArray?// 例如可以不用可选var items :NSMutableArray []var leftBtn:UIButton?override func viewDidLoad() {super.viewDidLoad()self.items NSMutableArray()// 初始化tableViewsetupViews()// 右边添加按钮setupRightBarButtonItem()// 左边删除按钮setupLeftBarButtonItem();}func setupViews(){self.tableView UITableView(frame:self.view!.frame)self.tableView!.delegate selfself.tableView!.dataSource selfself.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: cell)self.view.addSubview(self.tableView!)}func setupLeftBarButtonItem(){self.leftBtn UIButton(type: UIButtonType.Custom)self.leftBtn!.frame CGRectMake(0,0,50,40)self.leftBtn!.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)self.leftBtn!.setTitle(Edit, forState: UIControlState.Normal)self.leftBtn!.tag 100self.leftBtn!.userInteractionEnabled falseself.leftBtn!.addTarget(self, action: leftBarButtonItemClicked, forControlEvents: UIControlEvents.TouchUpInside)let barButtonItem UIBarButtonItem(customView: self.leftBtn!)self.navigationItem.leftBarButtonItem barButtonItem}func setupRightBarButtonItem(){let barButtonItem UIBarButtonItem(title: Add, style: UIBarButtonItemStyle.Plain, target: self, action: rightBarButtonItemClicked)self.navigationItem.rightBarButtonItem barButtonItem}func rightBarButtonItemClicked(){let row self.items.countlet indexPath NSIndexPath(forRow:row,inSection:0)self.items.addObject(1)self.tableView?.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Left)self.leftBtn!.userInteractionEnabled true}func leftBarButtonItemClicked(){if (self.leftBtn!.tag 100){// 设置当前tableView可编辑self.tableView?.setEditing(true, animated: true)self.leftBtn!.tag 200self.leftBtn?.setTitle(Done, forState: UIControlState.Normal)}else{self.tableView?.setEditing(false, animated: true)self.leftBtn!.tag 100self.leftBtn?.setTitle(Edit, forState: UIControlState.Normal)}}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}func tableView(tableView: UITableView, numberOfRowsInSection section: Int) - Int{return self.items.count}func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - UITableViewCell{let cell tableView .dequeueReusableCellWithIdentifier(cell, forIndexPath: indexPath) as UITableViewCellcell.textLabel!.text String(format: %i, indexPath.row1)return cell}// 指定可编辑的行func tableView(tableView: UITableView, setEditing indexPath: NSIndexPath) - Bool{return true}// 编辑完成func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){self.items.removeObjectAtIndex(indexPath.row)self.tableView?.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)if (self.items.count 0){self.leftBtn!.userInteractionEnabled false}}// 编辑样式func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) - UITableViewCellEditingStyle{return (UITableViewCellEditingStyle.Delete)}// 指定哪些行可以移动func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) - Bool{return true}// 移动完成func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath){self.tableView?.moveRowAtIndexPath(sourceIndexPath, toIndexPath: destinationIndexPath)self.items.exchangeObjectAtIndex(sourceIndexPath.row, withObjectAtIndex: destinationIndexPath.row)}// 限制在同一分区移动func tableView(tableView: UITableView, targetIndexPathForMoveFromRowAtIndexPath sourceIndexPath: NSIndexPath, toProposedIndexPath proposedDestinationIndexPath: NSIndexPath) - NSIndexPath {if sourceIndexPath.section proposedDestinationIndexPath.section {return proposedDestinationIndexPath}return sourceIndexPath}// 点击cellfunc tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){print(row %d,indexPath.row)}}转载于:https://www.cnblogs.com/wangxianggudu/p/5107733.html
http://www.pierceye.com/news/194351/

相关文章:

  • 电子商务网站建设a卷网站建设厘金手指排名二一
  • 网站空间便宜网站的信息管理建设的必要性
  • 校级特色专业建设网站博达站群网站建设教程
  • 有没有做任务的网站吗网站首页开发
  • 公司名字变了网站备案济南网站建设公司哪个好点呢
  • 图书馆网站建设的规章制度企业免费招聘网站
  • 效果图网站大全系统优化的例子
  • 京东的网站建设介绍网站开发要源码多少钱
  • 东莞网站制作公司报价企业定制
  • 创同盟做网站生成拼贴的网站
  • 网站备案号查电话号码商场网站开发
  • 手机网站建站教育模板下载泰州公司注册
  • 如何做商业网站推广西安市城乡建设管理局网站的公示栏
  • 上海做兼职哪个网站腾讯企业邮箱域名是什么
  • 霸州网站制作棋牌网站建设源码
  • 茶叶网站制作模板网页设计在安阳工资多少
  • 网站建设项目验收方案自己做捕鱼网站能不能挣钱
  • 微信网页网站怎么做我为群众办实事实践活动
  • 建设银行发卡银行网站福州 网站设计
  • 网站备案号码舟山高端网站建设
  • 买奢侈品代工厂做的产品的网站名建立网站 英语怎么说
  • 网站访问者qq计算机等级培训机构
  • 可以让外国人做问卷调查的网站济南优化seo网站建设公司
  • odoo做网站创建企业需要什么条件
  • 山西省旅游网站建设分析wordpress 个人介绍
  • 山东高级网站建设赚钱
  • 做网站大概要多少钱新建网站的外链多久生效
  • 天河区建设网站品牌网站建设小8蝌蚪
  • 深圳市企业网站seo点击软件小程序游戏开发公司
  • 南宁企业网站设计公怎么进wordpress