我使用UIPasteboard
在兩個UITextView
之間複製/粘貼文本。如何在viewWillDisappear上清除/清空粘貼板
代碼如下所示:
- (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:@""];
}
非常感謝! –
感謝您的回答。如果有人想要一個醜陋的長單行:'[[UIPasteboard generalPasteboard] setValue:@「」forPasteboardType:UIPasteboardNameGeneral];' –