テーブル ビューのセルを選択するときにハイライトを削除しようとしていますが、表示されるチェックマークを保持したいです。
cellForRowAtIndexPath でこれを試すと、次のようになります。
cell.backgroundView = UIView()
cell.backgroundView?.backgroundColor = UIColor.clearColor()
行全体ではなく、チェックマークの下のハイライトのみを削除します(添付の画像を参照)。
cellForRowAtIndexPath でこれを試すと、次のようになります。
cell.selectionStyle = UITableViewCellSelectionStyle.None
チェックマークが表示されなくなりました。
更新:これを試してみましたが、チェックマークを付けなくなった cell.selectionStyle と同じことを行います
func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
これを行う良い方法は何ですか?チェックボックスのように機能させたいのですが、青いハイライトを発生させたくありません。TableView は動的に生成されます。
checkBoxView = UITableView()
checkBoxView.frame = CGRect(x: qView.bounds.midX, y: qView.bounds.midY, width: qView.bounds.width - 100, height: qView.bounds.height/1.5)
checkBoxView.center = CGPointMake(qView.bounds.midX, qView.bounds.midY)
checkBoxView.delegate = self
checkBoxView.dataSource = self
checkBoxView.tag = 100
checkBoxView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
checkBoxView.setEditing(true, animated: true)
self.qView.addSubview(checkBoxView)
テーブル ビュー機能:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.checkBoxContent.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = checkBoxView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
cell.textLabel?.text = self.checkBoxContent[indexPath.row]
cell.backgroundColor = UIColor.clearColor()
cell.tintColor = UIColor.greenColor()
return cell
}
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle(rawValue: 3)!
}