首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何对此用例中的表视图单元格进行排序

如何对此用例中的表视图单元格进行排序
EN

Stack Overflow用户
提问于 2018-08-01 21:52:47
回答 1查看 803关注 0票数 1

在Swift 4中对此表进行排序的最佳实践是什么?

A-Z

代码语言:javascript
运行
复制
    override func viewDidLoad() {

        super.viewDidLoad()

        list = [ ghost(name:"alphabet".localized, id:"1"),
             ghost(name:"élephant".localized, id:"2"),
             ghost(name:"delegate".localized, id:"3")]
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1 
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if filtering() { 
            return filter.count 
        }
        return list.count 
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "library", for: indexPath)
        var data: ghost

        if filtering() { 
            data = filter[indexPath.row] 
        }
        else { 
            data = list[indexPath.row] 
        }

        cell.textLabel!.text = data.name
        return cell 
    }

我经常使用翻译后的字符串。所以,如果这个表可以用不同的语言按字母顺序加载,那就太好了。有人能帮我一下吗?我找遍了整个互联网,太累了.非常感谢!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51635105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档