gpt4 book ai didi

ios - 如何清除/清空 viewWillDisappear 上的粘贴板

转载 作者:可可西里 更新时间:2023-11-01 03:35:59 27 4
gpt4 key购买 nike

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

代码如下所示:

- (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");
}
}

即使这样也无济于事(NSLog 返回: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 解决方案)

关于ios - 如何清除/清空 viewWillDisappear 上的粘贴板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11067554/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com