Missing copy / paste menu in UITextField / UIWebView

I have a problem and I cannot find a workaround for her.

I have a view with an implementation of UIWebView and UITextField . In both cases, when I click, I do not get the copy / paste menu.

There is text in the text of the UIWebView (text only), and I can select a word or paragraph or make a magnification glass and manually select the text I want.

On the other hand, UITextField can accept input and work as intended, with the exception of copy / paste functions.

Nothing is subclassed. I only need the default iOS implementation for copy / paste functions.

This problem is not in one view. I have another UIWebView with the same problem elsewhere, so I think this is a global problem.

I did everything obvious (importing UIKit and Foundation frameworks, assigning properties, release, etc.), but again I was stuck on this.

What can interact / interfere with such simple functionality by disabling it? Moreover, always within the framework of the simplest implementation, what else is needed for this? (any infrastructure is missing, any property, etc.).

Such a simple thing, and I'm stuck with it. If someone has any idea, they really appreciate him.

==== Edit ====

The problem is not caused by my code in any view or class.

I added a new view (the application is based on a time sheet) with only UITextField and UITextView with the default text "Lorem Ipsum". In textView, I can also select text, but there is no menu to copy / paste / select / select All. This also happens in the text box (empty) where the paste menu is not displayed (I copy text from another application, such as Safari or Notes).

It seems that the problem elsewhere affects the universal application in all views.

I deleted the links to Frameworks and returned them, but nothing happened. I'm still trying to figure out where it comes from.

+6
source share
3 answers

I had the same problem: everything else worked correctly, but all of the UITextView missing from the copy / paste / select menu globally across all applications.

After some experimentation, I found that the reason was either:

The property "Visible at startup" is not set in a window in MainWindow.xib

OR

There is no call to [self.window makeKeyAndVisible] inside application:didFinishLaunchingWithOptions: the AppDelegate method.

It works great after fixing any of them. Give it a try.

+7
source

Make sure you implement:

 //init your menu somewhere, appropiately - (id) initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { NSMutableArray *items = [[[UIMenuController sharedMenuController] menuItems] mutableCopy]; if (!items) items = [[NSMutableArray alloc] init]; UIMenuItem *menuItem; menuItem = [[UIMenuItem alloc] initWithTitle:@"Undo" action:@selector(undo:)]; [items addObject:menuItem]; [menuItem release]; menuItem = [[UIMenuItem alloc] initWithTitle:@"Redo" action:@selector(redo:)]; [items addObject:menuItem]; [menuItem release]; [[UIMenuController sharedMenuController] setMenuItems:items]; [items release]; } return self; } //allow other items to appear and yours too :) Perhaps you are missing this? - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if ([super canPerformAction:action withSender:sender]) { return YES; } else { //write your code here if (action == @selector(undo:) && [self.undoManager canUndo]) return YES; if (action == @selector(redo:) && [self.undoManager canRedo]) return YES; } return NO; } //Do your actions - (void)undo:(id)sender{ //do your stuff here } - (void)redo:(id)sender{ //do your stuff here } 
+1
source

OK, I found a solution. This has nothing to do with the code or properties of objects. Its more or less "implementation" of Xcode4.

When a new generic project is created, xcode places AppDelegate at the root of the project and 2 more AppDelegates in each folder, one for the iPad and the other for the iPhone.

The root delegate of the application looks like

 #import <UIKit/UIKit.h> @interface SampleAppDelegate : NSObject <UIApplicationDelegate> { } @property (nonatomic, retain) IBOutlet UIWindow *window; 

from

 #import "SampleAppDelegate.h" @implementation SampleAppDelegate @synthesize window=_window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self.window makeKeyAndVisible]; return YES; } - (void)dealloc { [_window release]; [super dealloc]; } @end 

IPhone and iPad app Delegates do not have a window link.

If the root AppDelegate is deleted and the β€œwindow” code is moved in each device-specific AppDelegate, the All / Copy / Paste menu (or any other) appears again.

This happened to me in the first new xcode4 that I created. I can't remember well if xcode3 had a similar implementation (but I think not).

0
source

Source: https://habr.com/ru/post/890941/


All Articles