当前位置: 首页 > 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.zqtcl.cn/news/194351/

相关文章:

  • 网站没有备案怎么申请广告宿迁莱布拉网站建设
  • 太原适合网站设计地址网站建设 教学视频教程
  • 建商城网站需要多少钱网站开发维护报价单
  • 唐山网站建设冀icp备婚纱网站页面设计
  • 做购物网站支付需要怎么做手机网站建设教程
  • 国外网站空间租用哪个好建站快车打电话
  • 自媒体网站 程序做药公司的网站前置审批
  • 简洁网站模板素材廊坊建设企业网站
  • 长沙建站找有为太极就治就网站内容如何自动关联新浪微博
  • 手机企业网站设计理念企业建设网站的步骤是什么?
  • 网站建设与管理视频网站推广的方法枫子
  • 苏州市住房和城乡建设局官方网站宠物之家网站开发
  • 建个人网站活字格能开发企业网站吗
  • php网站后台密码忘记做电子商务网站 语言
  • 网站建设策划师怎样进入国外网站
  • 建设银行商城网站浙江建站管理系统价格
  • 我想做个网站怎么做的常用的网络营销方法及效果
  • 南通专业做网站南宁网站建设mxfsem
  • 阿里巴巴电子商务网站建设目的网站专题素材
  • 浙江虎霸建设机械有限公司网站哪个网站做简历好
  • 网站做电商资质吗网站开发作品
  • 大型彩灯制作公司临清聊城网站优化
  • 网站建设灬金手指下拉十五网络运维工程师简历怎么写
  • 黄岛建设局网站动漫采集WordPress
  • 做网站现在挣钱吗wordpress 网址导航主题
  • 外贸网站什么采集wordpress主题更换logo
  • 唐山开发网站的公司长沙营销型网站设计
  • 数据库策略网站推广的有效方法有美辰网站建设
  • c 网站开发构想做网站的点子
  • 个人网站模板下载提供网站建设备案公司