2016-09-21 3 views
0

私のアイデアは、このビューが表示されるときです。私はそれを場所によって検出させたい。シンガポールのユーザーならシンガポールセルが強調表示されます。それを可能にする方法はありますか?私は、この関数を参照してくださいましたが、viewDidAppearのハイライト

ここdidHighlightRowAtIndexPath

コーディングビュー 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) 
     } 
    } 
} 
+0

http://stackoverflow.com/questions/2035061/select-tableview-row-programmatically – Azzaknight

答えて

0

保存するための変数を取ります現在地のインデックス

位置upadate方法で位置更新 において
var loctionIndex: Int = -1 

更新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 
} 
+0

私は私の新しいコーディングをコメントしました。私の状況では上記のurコードを使用する方法を知りません。 –

0

における行のセル内のいくつかのロジックを次のようにそのloctionIndexを使用してテーブルビューの単一の行をリロード最初にこのコードを使用して国を検出してください:

let currentLocale = NSLocale.currentLocale() countryCode = currentLocale.objectForKey(NSLocaleCountryCode)を?両方がperticularセルそのhightlightと同じであれば、国の文字列を比較するよりも、文字列

..

+0

ええ、私はそこに論理を見ることができます。しかし、私はその特定の細胞をどのように強調表示するのか知りません。どの機能を使うべきですか? –

+0

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } //ここで何かを実行 } - (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath { } } –

関連する問題