Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear/empty pasteboard on viewWillDisappear

I use UIPasteboard to copy/paste text between two UITextView.

Code looks like this:

- (void)viewDidLoad {
   [super viewDidLoad];
   pasteBoard = [UIPasteboard generalPasteboard]; //it is declared in .h as UIPasteboard *pasteBoard;
}

-(IBAction)doCopyBtn {
    if (![toCopyTextView.text isEqualToString:@""]){
        pasteBoard.string = toCopyTextView.text;
        NSLog(@"pasteb1 %@", pasteBoard.string);
    } else {
        NSLog (@"error! enter smth");
    }
}

-(IBAction)doPasteBtn {
    if (![pasteBoard.string isEqualToString:@""]){ 
        toPasteTextView.text = pasteBoard.string;
        NSLog(@"pasteb2 %@", pasteBoard.string);
    } else {
        NSLog (@"error! enter smth");
    }
}

And even this cant help (NSLog returns: pasteb2 (null))

-(void) viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [pasteBoard setString:@""]; 
}
like image 769
Aleksey Potapov Avatar asked Jun 16 '12 22:06

Aleksey Potapov


People also ask

How to empty the clipboard in Windows 10?

Here’s how to empty the clipboard. To delete all clips or an individual clip, first open the Clipboard task pane. On the Home tab, in the Clipboard group, click the Clipboard dialog box launcher.

How do I use subclasses to override the viewdidappear method?

Subclasses can override this method and use it to commit editing changes, resign the first responder status of the view, or perform other relevant tasks. For example, you might use this method to revert changes to the orientation or style of the status bar that were made in the viewDidAppear (_:) method when the view was first presented.

How to view clipboard history in Windows 10?

or view the history of the contents of the clipboard. 1. Go to start and type in the search box “RUN” and hit enter. 2. In the command window type in cmd /c “echo off | clip” in the text box and press enter. 3. Instantly a window will come and disappear in front of you.

How to clear clipboard in Microsoft Word 2016?

Clear the clipboard 1 On the Home tab, in the Clipboard group, click the Clipboard dialog box launcher. 2 The Clipboard task pane appears on the left side of your spreadsheet and shows all clips in the clipboard. 3 To clear the entire clipboard, click the Clear All button. More items...


2 Answers

iOS – UIPasteboard

Try the following:

    UIPasteboard *pb = [UIPasteboard generalPasteboard];
    [pb setValue:@"" forPasteboardType:UIPasteboardNameGeneral];

Arab_Geek's response is correct but available for Cocoa (and I suspect you are looking for an iOS solution)

like image 159
Riddick Avatar answered Sep 23 '22 20:09

Riddick


OS X - NSPasteboard

Here you go ..

NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb declareTypes: [NSArray arrayWithObject:NSStringPboardType] owner: self];
[pb setString: @"" forType: NSStringPboardType];
like image 22
AK_ Avatar answered Sep 25 '22 20:09

AK_