How to navigate to next UIViewController using UITextView in an UINavigationBar

走远了吗. 提交于 2019-12-12 02:14:09

问题


I'm trying to use an UITextView as a button, and after clicking on the UITextView it should pop to to another UIViewController (not the root one, next one).

Using an UIButton works fine (by dragging to next UIViewController and choosing "Push" as the segue type, without doing any coding). But, doing the same thing with a UITextView does not work!

So, my question is how to navigate to the next view controller using an UITextField?


回答1:


Try adding a UITapGestureRecognizer to the text view and using that callback to trigger a segue.

I don't think you can do this without code.




回答2:


Add Tap Gesture to UITextView

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mySelector)];
  tapRecognizer.numberOfTapsRequired = 1;
[_textView addGestureRecognizer:tapRecognizer];

Push or Present UIVieWController in UITapGestureRecognizer action method.

-(void)mySelector
        {
        // Navigate  to  next view controller
        }



回答3:


Set the userInteractionEnabled attribute?

textView.userInteractionEnabled = YES;

You should be able to use the textView like a button...




回答4:


UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myTapped:)];
tapRecognizer.numberOfTapsRequired = 1;
[txtView addGestureRecognizer:tapRecognizer];

    -(void)myTapped::(UIGestureRecognizer *)gesture
    {
                // Do what you want here
    }

try this code



来源:https://stackoverflow.com/questions/18976487/how-to-navigate-to-next-uiviewcontroller-using-uitextview-in-an-uinavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!