gpt4 book ai didi

ios - viewDidAppear 时突出显示

转载 作者:行者123 更新时间:2023-11-30 13:03:57 29 4
gpt4 key购买 nike

我的想法是这个 View 何时出现。我想让它按位置检测。所以如果用户在新加坡。新加坡细胞将被重点关注。有什么办法可以实现吗?我确实看到了这个功能,但不知道如何使用

didHighlightRowAtIndexPath

这是 View enter image description here

编码:

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)
}
}
}

最佳答案

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

var loctionIndex: Int = -1

更新位置更新器中的locationIndex在位置更新方法中,使用该 locationIndex 重新加载单行表格 View ,如下所示

if loctionIndex != -1 {
let indexPath = NSIndexPath(forRow: loctionIndex, inSection: 0)
tableview.reloadRowsAtIndexPaths([indexPath], withRowAnimation:UITableViewRowAnimation.None)
}

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

 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
}

关于ios - viewDidAppear 时突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39611256/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com