Swift-tableView1

本篇文章里面主要有两个内容

1.字符串的截取
2.tableview开启删除功能
字符串的截取

 private let lyric = "我和我的祖国一刻也不能分割,无论我走到哪里都流出一首赞歌,我歌唱每一座高山我歌唱每一条河,袅袅炊烟小小村落路上一道辙,你用你那母亲的脉搏和我诉说,我的祖国和我像海和浪花一朵,浪是海的赤子海是那浪的依托,每当大海在微笑我就是笑的旋涡,我分担着海的忧愁分享海的欢乐,永远给我碧浪清波心中的歌,啦啦…永远给我碧浪清波心中的歌"
 dataSource = lyric.split(separator: ",").map(String.init)

开启删除功能(实现下面方法)

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        
        return .delete
    }
    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "删除"
    }
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath){
        if editingStyle == .delete {
            // 当点击了删除按钮
            dataSource.remove(at: indexPath.row)
            // 刷新
            tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.bottom)
                
        }
       
    }

demo地址

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,807评论 1 32
  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,951评论 1 180
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 12,733评论 28 53
  • 信任包括信任自己和信任他人 很多时候,很多事情,失败、遗憾、错过,源于不自信,不信任他人 觉得自己做不成,别人做不...
    吴氵晃阅读 11,352评论 4 8
  • 步骤:发微博01-导航栏内容 -> 发微博02-自定义TextView -> 发微博03-完善TextView和...
    dibadalu阅读 8,393评论 1 3