I have searched (so far unsuccessfully) for an (understandable) solution to this problem. My app uses UITableViews with cells that contain UITextViews. I want to be able to select the UITextView rather than the underlying cell. I understand that I need to make it the firstresponder but cannot find out how to do this. I am using Swift 2.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath)
{
switch (getTipsInfo(viewName, sectionNumber: indexPath.section, tipOrder: indexPath.row).tipType) {
case "URL":
defaults.setObject(getTipsInfo(viewName, sectionNumber: indexPath.section, tipOrder: indexPath.row).tipLinkName, forKey: "URL")
myStack.push(getViewNC(viewName))
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier(browserNC)
self.presentViewController(vc, animated: true, completion: nil)
case "link":
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
myStack.push(getViewNC(viewName))
let vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier(getTipsInfo(viewName, sectionNumber: indexPath.section, tipOrder: indexPath.row).tipLinkName)
self.presentViewController(vc, animated: true, completion: nil)
default:
()
} // end switch
}
Assuming that you want to make this UITextView
the first responder immediately upon it loading, you could put the following code inside of your awakeFromNib
method inside of a custom UITableViewCell
class.
self.myTextView.becomeFirstResponder()
This will make it so that the cursor will automatically be inside of myTextView
whenever this cell loads, and the keyboard will come up as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.