0

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.

Update - my code

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
}
4

1 回答 1

1

假设您想让UITextView它在加载后立即成为第一响应者,您可以将以下代码放入awakeFromNib自定义UITableViewCell类的方法中。

self.myTextView.becomeFirstResponder()

这将使光标myTextView在此单元格加载时自动位于其中,并且键盘也会出现。

于 2015-10-21T19:40:34.120 回答