fselva fselva - 2 months ago 12
Swift Question

UITextView tap event to set an UITableView visible

I'm working on a swift application,

Let's say, I have a simple

UITextView
and I want, If the user tap on it, open a
UITableView
.

How I imagine the thing, is to make an
UITableView
set as
invisible
and when we tap the
UITextView
, the
UITableView
becomes
visible
. and when we tap a button on a
custom cell
of the
UITableView
, the
UITableView
becomes invisible again and the
UITextView
text get what was on the cell.

Is it just possible? I mean, the only
Received Actions
available on a UITextView is copy, cut, paste... Nothing like
Touch Down
,
On Click
or something like this..

I don't succeed to find informations about this on swift, if somebody already tried something like this?

Thanks in advance. Regards,

fselva

Answer

You can set Editing did began action like shown in below image:

enter image description here

By creating this method when user tap on textField that method will call and into that method you can show your tableView as shown below:

@IBAction func editingBegan(sender: AnyObject) {
    table.hidden = false
}

After that if you want to hide tableView when user press button on custom cell then just create a action for that button in your custom cell class and you can hide tableView.