Reputation: 55
I'm trying to fix an issue for two days but I really don't know what to do. I tried several solutions but nothing helped.
This is the situation: I have a UIViewController and I've added a subclass of UITextView as subview.
-(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
_textView = [[DPTextView alloc] initWithFrame:self.view.bounds];
[_textView setText:[NSString stringWithContentsOfFile:_path encoding:NSUTF8StringEncoding error:nil]];
_textView.editable = NO;
_textView.selectable = YES;
_textView.delegate = self;
_textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:_textView];
//[self.view becomeFirstResponder];
//[self becomeFirstResponder];
//[_textView becomeFirstResponder];
}
When I open this UIViewController, I see the text. If I select the text, I don't see the UIMenuController. I've already overriden some methods of the subclass of UITextView (DPTextView), like the following:
-(BOOL)canBecomeFirstResponder {
return TRUE;
}
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(copy:))
return YES;
return NO;
}
But it doesn't appear. After some time I've noticed that the UIMenuController appears if I follow some steps:
Following those steps, the UIMenuController appears when I select text into Controller2! I don't know really why! I thought something happened when pressing the search bar, like the controller becomes the first responder or something similar (and I've already tried to call "becomeFirstResponder", as you can read in the code above -- the commented lines of code).
Note that if I tap and hold UITableViewCell in Controller1, I should get UIMenuController too, because I've implemented those methods:
-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
return TRUE;
}
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
return (action == @selector(copy:));
}
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[[UIPasteboard generalPasteboard] setString:cell.textLabel.text];
}
}
But it doesn't appear here too. It appears if after using the search controller, so the same situation.
Any suggestion? I don't know if this can help but Controller1 and Controller2 are presented modally.
Upvotes: 2
Views: 74