我想在我的UIViewController中为我附加的UITextView处理粘贴事件,这样如果粘贴的数据是文本或html,它应该像往常一样粘贴数据,但是如果它是其他类似的东西我想以另一种方式在本地存储数据,而不是将其粘贴到UITextView中(因为它无法做到这一点)。
我该怎么做呢?在我可以从Apple找到的唯一示例中,他们知道他们粘贴的数据类型。甚至让我的控制器中的“ - (void)paste:(id)sender”方法在我的UITextView中有一个粘贴事件时被调用也让我感到厌烦。
谢谢
答案 0 :(得分:1)
您可以使用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协议实现粘贴方法。