gpt4 book ai didi

iphone - 处理 UIViewController 中的粘贴事件

转载 作者:行者123 更新时间:2023-12-03 19:22:56 24 4
gpt4 key购买 nike

我想在我的 UIViewController 中为我附加的 UITextView 处理粘贴事件,这样如果粘贴的数据是文本或 html,它应该像平常一样粘贴数据,就像它已经做的那样,但如果它是其他类似的东西图像或 pdf 或任何东西,我想以另一种方式在本地存储数据,而不是将其粘贴到 UITextView 中(因为它不能执行此操作)。

我该如何去做这件事呢?在我能从苹果找到的唯一例子中,他们知道他们粘贴的数据的类型。当我的 UITextView 中存在粘贴事件时,甚至在我的 Controller 中调用我的“-(void)paste:(id)sender”方法也让我感到困惑。

谢谢

最佳答案

您可以使用方法canReadObjectForClasses:options:测试某些东西而不实际检索值。

例如,测试字符串:

NSArray *classes = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];

if ([[NSPasteboard generalPasteboard] canReadObjectForClasses:classes options:options]) {
NSLog(@"yup, there is a string in here");
}

更新:

您可以通过这种方式检查粘贴板中的所有对象,只需在数组中添加您期望的任何类即可。

NSArray *classes = [NSArray arrayWithObjects:[NSURL class], [NSString class], nil];

使用UIResponderStandardEditActions实现粘贴方法的协议(protocol)。

关于iphone - 处理 UIViewController 中的粘贴事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3941773/

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