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?
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.
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
}
Set the userInteractionEnabled attribute?
textView.userInteractionEnabled = YES;
You should be able to use the textView like a button...
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