0

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.

Nilesh
  • 701
  • 5
  • 14
joe
  • 8,383
  • 13
  • 61
  • 109

2 Answers2

0

How about give action to each view that did same action as cell clicked. For example, if i'th view clicked, do samething as i'th cell did when it clicked.

rnsjtngus
  • 225
  • 1
  • 8
  • I am following your comment. – joe Nov 05 '15 at 09:07
  • No, it is not. Actually, I was interrupted by colleague's solution. Currently, I'm doing another problem. Thank you for your concern. – joe Nov 06 '15 at 02:11
0

His question hint me my solution.
UIWebView on UITableView prevents tablecell Selection

Use cell.myWebView.userInteractionEnabled = false; in tableView(..., cellForRowAtIndexPath,...)

Community
  • 1
  • 1
joe
  • 8,383
  • 13
  • 61
  • 109