I know how to select the ordinary cell by implementing UILabel
.
However, my situation is a little bit harder than usual.
I have to render TeX from MathJax first and then put the rendered one to cell.
In actual application fruit
array will be replace by a TeX
code.
Here is my simplified code.
ViewController.swift :
import UIKit
class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableViewObject: UITableView!
var fruits = ["Apple", "Banana","Cherry", "Durian", "ElderBerry"];
override func viewDidLoad() {
super.viewDidLoad()
self.tableViewObject.delegate = self;
self.tableViewObject.dataSource = self;
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return fruits.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) as! MyCell;
cell.myLabel.text = String(UnicodeScalar(65 + indexPath.row));
cell.myWebView.loadHTMLString(fruits[indexPath.row], baseURL: nil);
cell.myWebView.scrollView.bounces = false;
cell.myWebView.scrollView.scrollEnabled = false;
return cell;
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int{
return 1;
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
/*
Implement something
*/
}
}
MyCell.swift :
import UIKit
class MyCell: UITableViewCell {
@IBOutlet weak var myLabel : UILabel!
@IBOutlet weak var myWebView : UIWebView!;
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
How to tap on the webview and then let iOS know that I clicked the cell?
Right now, I have to click "A, B, C, or D" to select them.