How to navigate to next UIViewController using UIT

2019-08-31 07:36发布

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?

4条回答
放荡不羁爱自由
2楼-- · 2019-08-31 08:00

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.

查看更多
闹够了就滚
3楼-- · 2019-08-31 08:03

Set the userInteractionEnabled attribute?

textView.userInteractionEnabled = YES;

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

查看更多
Fickle 薄情
4楼-- · 2019-08-31 08:06

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
        }
查看更多
欢心
5楼-- · 2019-08-31 08:09
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

查看更多
登录 后发表回答