如何在viewWillDisappear上清除/清空粘贴板 [英] How to clear/empty pasteboard on viewWillDisappear

查看:3090
本文介绍了如何在viewWillDisappear上清除/清空粘贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UIPasteboard 在两个 UITextView 之间复制/粘贴文本。



代码如下:

   - (void)viewDidLoad {
[super viewDidLoad];
pasteBoard = [UIPasteboard generalPasteboard]; //它在.h中声明为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);
}
}

c $ c> pasteb2(null))

   - (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[pasteBoard setString:@];
}


解决方案

iOS - UIPasteboard



请尝试以下操作:

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

Arab_Geek的回应是正确的但可用于Cocoa(我怀疑你正在寻找一个iOS解决方案) / p>

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:@""]; 
}

解决方案

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)

这篇关于如何在viewWillDisappear上清除/清空粘贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆