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

编码:
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)
}
}
}发布于 2016-09-21 08:51:17
取一个变量来存储当前位置的索引
var loctionIndex: Int = -1在位置更新器中更新loctionIndex,upadate方法使用该loctionIndex重新加载单行表视图,如下所示
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
}发布于 2016-09-21 10:54:43
首先使用以下代码检测国家:
设currentLocale = NSLocale.currentLocale()让countryCode =countryCode as?字符串
比国家字符串如果两者都是相同的高光,透细胞.
https://stackoverflow.com/questions/39611256
复制相似问题