我想处理我的附加UITextView的UIViewController中的粘贴事件,以便如果粘贴的数据是文本或html,它应该粘贴数据作为正常和它已经做了,但如果它是像图像或pdf或任何其他东西,我想以另一种方式存储本地数据,而不是粘贴到UITextView (因为它不能做到这一点)。
我该怎么做呢?在我能从Apple找到的唯一一个例子中,他们知道他们粘贴的数据的类型。甚至在我的UITextView中有一个粘贴事件时,让我的控制器中的"-(void) paste :(id)sender“方法被调用,我都没想到。
谢谢
发布于 2010-10-15 19:50:36
您可以使用方法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协议实现paste方法。
https://stackoverflow.com/questions/3941773
复制相似问题