首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >突出显示何时viewDidAppear

突出显示何时viewDidAppear
EN

Stack Overflow用户
提问于 2016-09-21 08:28:23
回答 2查看 77关注 0票数 0

我的想法是当这个观点出现的时候。我想让它通过位置来检测。所以如果新加坡的用户。将重点介绍新加坡单元。有什么办法让它成为可能吗?我确实看到了这个函数,但是我不知道如何使用它

didHighlightRowAtIndexPath

这是视图

编码:

代码语言:javascript
复制
class LanguageViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate {

    @IBOutlet weak var optionsTableView: UITableView!

    let titleArr = ["About", "Terms", "Privacy Policy", "Reset Password", "Change Language", "Logout"]

    var countryList = [AnyObject]()
    var languageList = [AnyObject]()
    var selectRow = Int()
    var selectLanguage = Int()
    var isSelect = Bool()
    var tempCountry = [String]()
    var tempLanguage = [String]()
    var countryLbl : String = "Country"
    var languageLbl : String = "Language"

    // MARK: - Activity Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        setupWhiteLeftButton()
        //self.navigationItem.title = ""

        for country in countryList{
            tempCountry.append(country["CountryName"] as! String)
        }
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView, didHighlightRowAtIndexPath indexPath: NSIndexPath) {
        indexPath.row == 0
    }

    // MARK: - UITableViewData Source & Delegate


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tempCountry.count
    }

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 40
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        optionsTableView.backgroundColor = UIColor.redColor()
        let cell = optionsTableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCountryTableViewCell
        cell.backgroundColor = UIColor.redColor()
        cell.titleLbl.text = tempCountry[indexPath.row]
        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if indexPath.row == 0 {
//            let storyboard2 = UIStoryboard(name: "Profile", bundle: nil)
//            let AboutVC = storyboard2.instantiateViewControllerWithIdentifier("AboutVC") as! AboutViewController
//            self.navigationController?.pushViewController(AboutVC, animated: true)
//            optionsTableView.deselectRowAtIndexPath(indexPath, animated: true)
        }
    }
}
EN

回答 2

Stack Overflow用户

发布于 2016-09-21 08:51:17

取一个变量来存储当前位置的索引

代码语言:javascript
复制
var loctionIndex: Int = -1

在位置更新器中更新loctionIndex,upadate方法使用该loctionIndex重新加载单行表视图,如下所示

代码语言:javascript
复制
if loctionIndex != -1 {
     let indexPath = NSIndexPath(forRow: loctionIndex, inSection: 0)
     tableview.reloadRowsAtIndexPaths([indexPath], withRowAnimation:UITableViewRowAnimation.None)
}

在这里写一些逻辑在单元格中行的索引方法。

代码语言:javascript
复制
 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    optionsTableView.backgroundColor = UIColor.redColor()
    let cell = optionsTableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCountryTableViewCell
    if loctionIndex == indexPath.row {
    cell.backgroundColor = UIColor.greenColor()
} else {
     cell.backgroundColor = UIColor.redColor()
  }
    cell.titleLbl.text = tempCountry[indexPath.row]
    return cell
}
票数 0
EN

Stack Overflow用户

发布于 2016-09-21 10:54:43

首先使用以下代码检测国家:

设currentLocale = NSLocale.currentLocale()让countryCode =countryCode as?字符串

比国家字符串如果两者都是相同的高光,透细胞.

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

https://stackoverflow.com/questions/39611256

复制
相关文章

相似问题

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